package firstproject;
import java.util.Scanner;
import java.text.NumberFormat;
public class MileageApp {
public static void main(String[] args){
//create scanner object
Scanner sc = new Scanner(System.in);
String repeat = "yes";
while(repeat.equalsIgnoreCase("yes")){
//Display Welcome massage
System.out.println("Welcome to MPG Calculator ");
System.out.println("");
System.out.print("What is your Name: ");
String name = sc.nextLine();
System.out.print("What is your Car Model: ");
String model = sc.nextLine();
System.out.print("What is your Car Make: ");
String make = sc.nextLine();
System.out.print("What is your starting Odometer reader: ");
double startingMileage = sc.nextDouble();
System.out.print("What is your ending odometer reader: ");
double endingMileage = sc.nextDouble();
System.out.print("What is your Starting Gallons of Gas in the Tank:");
double startingGallons = sc.nextDouble();
System.out.print("What is your Ending Gallons of Gas in the Tank:");
double endingGallons = sc.nextDouble();
//Calculate mileage traveled
double mileageTraveled = endingMileage - startingMileage;
//calculate gallons of gas
double gasUsed = startingGallons - endingGallons;
//calculate Mileage per gallon
double mpg = mileageTraveled / gasUsed;
//price of a gas of gallon
final double GAS_PRICE = 3.85;
//calculate travel Cost
double gasCostPerGallon = GAS_PRICE * gasUsed;
String rate = "";
//if else statement
if (mpg <= 20){
rate = "Gas Guzzler";
}
else if (mpg <= 30 && mpg >= 20){
rate = "Good";
}
else if (mpg > 30){
rate = "Amazing";
}
//Create currency formatting object
NumberFormat cf = NumberFormat.getCurrencyInstance();
NumberFormat df = NumberFormat.getNumberInstance();
//display summary
System.out.println("Welcome to the MPG Calculator!");
System.out.println("");
System.out.println("Customer Name: " + name );
System.out.println("Car Model: " + model );
System.out.println("Car Make: " + make);
System.out.println("Starting Odometer Reading: " + startingMileage);
System.out.println("Ending Odometer Reading: " + endingMileage);
System.out.println("Miles Traveled: " + mileageTraveled);
System.out.println("Gallons of Gas Used: " + gasUsed);
System.out.println("Cost of Gas per Gallon: " + cf.format(gasCostPerGallon));
System.out.println("Mile Per Gallon Usage (MPG): " + df.format(mpg));
System.out.println("Car MPG rating is: " + rate);
System.out.println("");
//ask if they want to continue
System.out.print("Do you want to continue? (Yes/No)");
System.out.println("");
repeat = sc.next();
}
System.out.println("Thank you for using Mileage App!");
sc.close();
}
}
Ok my problem is when say yes to continue, it prints out:
Welcome to MPG Calculator
What is your Name: What is your Car Model:
instead of just what is your name
please tell me what is wrong with my code thank you