The program should prompt the user to enter the number of ga
Solution
MileageCalc.java
import java.text.DecimalFormat;
 import java.util.Scanner;
 public class MileageCalc {
  
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println(\"Welcome to the mileage calculator\");
        System.out.println(\"This program will calculate th miles per galloon for you for three tanks of gas after you have entered the gallons used miles driven\");
        double sum = 0;
        DecimalFormat df = new DecimalFormat(\"0.0\");
        for(int i=1; i<=3; i++){
        System.out.print(\"Enter the number of gallons used for tank #\"+i+\": \");
        double gallons = scan.nextDouble();
        System.out.print(\"Enter the number of miles drven: \");
        double miles = scan.nextDouble();
        double milesPerGallon = miles/gallons;
        System.out.println(\"*** The miles per gallon for ths tank is \"+df.format(milesPerGallon));
        sum = sum + Double.valueOf(df.format(milesPerGallon));
        }
        System.out.println(\"Your overall average miles per gallon for three tanks is \"+df.format((sum/3)));
        System.out.println(\"Thank you for using this program. Goodbye\");
       
    }
}
Output:
Welcome to the mileage calculator
 This program will calculate th miles per galloon for you for three tanks of gas after you have entered the gallons used miles driven
 Enter the number of gallons used for tank #1: 12.8
 Enter the number of miles drven: 287.1
 *** The miles per gallon for ths tank is 22.4
 Enter the number of gallons used for tank #2: 10.3
 Enter the number of miles drven: 200.2
 *** The miles per gallon for ths tank is 19.4
 Enter the number of gallons used for tank #3: 5.2
 Enter the number of miles drven: 120.9
 *** The miles per gallon for ths tank is 23.2
 Your overall average miles per gallon for three tanks is 21.7
 Thank you for using this program. Goodbye


