Answer:
A java application was designed to provide a program output in a logical manner and incorporates appropriate data types.
Step-by-step explanation:
Solution
Program:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//for taking console input
Scanner sc = new Scanner(System.in);
//varibles for holding the values
String brand, model;
int year, startOdo, endOdo;
double gallons, mpg;
//taking user inputs
System.out.print("Enter Car Brand: "); brand = sc.nextLine();
System.out.print("Enter Car Model: "); model = sc.nextLine();
System.out.print("Enter Car Year: "); year = sc.nextInt(); sc.nextLine();
System.out.print("Enter Starting Odometer reading: "); startOdo = sc.nextInt(); sc.nextLine();
System.out.print("Enter Ending Odometer reading: "); endOdo = sc.nextInt(); sc.nextLine();
System.out.print("Enter gallons used: "); gallons = sc.nextDouble(); sc.nextLine();
//calculating the mpg by dividing the total distance with fuel used
mpg = (endOdo - startOdo) / gallons;
//showing the output
System.out.println("\\*********Car Details*********");
System.out.println("Brand: "+brand);
System.out.println("Model: "+model);
System.out.println("Year: "+year);
System.out.println("Starting Odometer: "+startOdo);
System.out.println("End Odometer: "+endOdo);
System.out.println("Gallons Used: "+gallons);
System.out.printf("MPG: %.2f",mpg);
sc.close();
}
}