It is supposed to go back into the loop and if 0 is entered for miles, it will end the program. Why is it getting hung up after my while?
import java.util.Scanner;
public class TravelTimeApp
{
// global variables
private static double miles;
private static double milesPerHour;
private static double hours;
private static int minutes;
private static int hoursInt;
// default constructor to initialize the class's variables
public TravelTimeApp()
{
miles = 0;
milesPerHour = 0;
hours = 0;
minutes = 0;
hoursInt = 0;
}
public static void main(String[] args)
{
// get personal heading
BachHeading.getHeading ("Assignment 3 - Working With Data");
// display a welcome message
System.out.printf("%snn", " Calculate Travel Time");
// create the Scanner object
Scanner sc = new Scanner(System.in);
System.out.printf(" Enter miles traveled, or a zero (0) to exit -> ");
miles = sc.nextDouble();
if (miles == 0)
{
System.out.printf("n Program completed.");
BachDate.printfDate();
BachDate.printfTime();
System.exit(0);
}
while (miles != 0)
{
// get input from the user
System.out.printf("%s", " Enter miles per hour rate of travel -> ");
double mph = sc.nextDouble();
System.out.printf("%n");
// calculate the travel time in hours with decimal division
double hours = miles / mph;
// get number of minutes as an int
int minutes = (int) (hours * 60);
// use integer arithmetic to get hours and minutes as int values
int hoursInt = minutes / 60;
minutes = minutes % 60;
// display the result
System.out.printf("n Estimated Travel Time (%,.1f miles at %,.1f mph)", miles, milesPerHour);
System.out.printf("n Hours%,10dn", hoursInt);
System.out.printf(" Minutes%,8dnn", minutes);
} // end while
} // end main
} // end TravelTimeApp
/** Murach, J. ( 2011). Murachs Java Programming, Training and Reference,
4th Edition, Fresno, CA: Mike Murach & Associates, Inc.
Modifications by W. Bowers, 2016
Additional modifications by R. Bach, 2016
*/
import java.util.Scanner;
public class TravelTimeApp
{
// global variables
private static double miles;
private static double milesPerHour;
private static double hours;
private static int minutes;
private static int hoursInt;
// default constructor to initialize the class's variables
public TravelTimeApp()
{
miles = 0;
milesPerHour = 0;
hours = 0;
minutes = 0;
hoursInt = 0;
}
public static void main(String[] args)
{
// get personal heading
BachHeading.getHeading ("Assignment 3 - Working With Data");
// display a welcome message
System.out.printf("%snn", " Calculate Travel Time");
// create the Scanner object
Scanner sc = new Scanner(System.in);
System.out.printf(" Enter miles traveled, or a zero (0) to exit -> ");
miles = sc.nextDouble();
if (miles == 0)
{
System.out.printf("n Program completed.");
BachDate.printfDate();
BachDate.printfTime();
System.exit(0);
}
while (miles != 0)
{
// get input from the user
System.out.printf("%s", " Enter miles per hour rate of travel -> ");
double mph = sc.nextDouble();
System.out.printf("%n");
// calculate the travel time in hours with decimal division
double hours = miles / mph;
// get number of minutes as an int
int minutes = (int) (hours * 60);
// use integer arithmetic to get hours and minutes as int values
int hoursInt = minutes / 60;
minutes = minutes % 60;
// display the result
System.out.printf("n Estimated Travel Time (%,.1f miles at %,.1f mph)", miles, milesPerHour);
System.out.printf("n Hours%,10dn", hoursInt);
System.out.printf(" Minutes%,8dnn", minutes);
} // end while
} // end main
} // end TravelTimeApp