Daily Spending Program §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Daily Spending
// caleb brown
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Item Name:");
String itemName = scanner.nextLine();
System.out.println("Enter Item Price:");
double itemPrice = scanner.nextDouble();
System.out.println("Enter the amount of days you want to calculate:");
int days = scanner.nextInt();
double total = itemPrice * days;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("The total cost of " + itemName + " for " + days + " days is $" + df.format(total));
}
}
Area and Circumference of a Circle §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Area and Circumference of a Circle
// caleb brown
Scanner input = new Scanner(System.in);
System.out.print("Enter the radius of the circle (cm): ");
double radius = input.nextDouble();
double area = Math.PI * Math.pow(radius, 2);
double circumference = 2 * Math.PI * radius;
DecimalFormat df = new DecimalFormat("#.###");
System.out.println("The area of the circle is " + df.format(area) + " cm^2");
System.out.println("The circumference of the circle is " + df.format(circumference) + " cm");
}
}
Motion of a Car §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Motion of a Car
// caleb brown
Scanner input = new Scanner(System.in);
System.out.println("Enter the distance the car must travel (km): ");
double distance = input.nextDouble();
System.out.println("Enter the speed of the car (km/h): ");
double speed = input.nextDouble();
double time = distance / speed;
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("The time it will take to travel " + distance + " km at " + speed + " km/h is " + df.format(time) + " hours.");
}
}
View Next Assignment