Why is it getting hung up after my while

Assignment Help JAVA Programming
Reference no: EM131602806

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

Reference no: EM131602806

Questions Cloud

How you will handle your proposed ethical dilemma : Describe how you will handle your proposed ethical dilemma from a Christian worldview perspective. Provide at least three references to scholarly resources.
Write a complete java program that prints the values : Write a complete java program that does - this should be the functionally for all x, w and z.
Identify trends and current research conclusions : Identify trends and current research conclusions related to the selected factors. Describe the company you selected, the industry in which it operates.
American recovery and reinvestment act : The American Recovery and Reinvestment Act of 2009 (ARRA) was passed by President Obama and Congress in response to the recession of 2007-2009.
Why is it getting hung up after my while : 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?
Define incorporate policy advocacy : Explain the steps a social workers might take to incorporate policy advocacy on their practice based insight, experiences
Discuss the bcp strategies discussed in the video : Discuss the BCP strategies discussed in the video. Research and find at least three more recommendations for developing a BCP.
Develop a successful health advocacy campaign : Develop a successful health advocacy campaign, you must have a clear idea of the goals of your campaign program .
Define mechanism on the development of psychoanalysis : Discuss the influences of evolutionary theory and of the notion of mechanism on the development of psychoanalysis

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd