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

  Analyze a current event

Analyze a current event ( you may use an article from the Wall Street Journal, Financial Times, or New York Times, published this week) using any of the principles that you've learned in this class. 2 pages, double spaced, cite article.

  Write java application that lets you create strong password

Write a java application that lets you create a strong password. The password should follow the following some criteria: (use your own creativity to come up with specific requirements).

  Display the value of the tostring method of a customer type

display the value of the toString method of a customer type

  Create a graphical application stackdemogui

Create a graphical application StackDemoGUI that provides a button for push and pop from a stack, a text field to accept a string as input for push, and a text area to show the contents of the stack after each operation.

  Handling the unexpected in life

100-300 Words. We often are handling the unexpected in life.  Kids and pets can offer many of these unexpected occurrences. Where do you see life's every day exception and how would the programming look for those?  Humor is appreciated.

  Prove that the difference of two odd integers is even

Prove that the difference of two odd integers is even. Give a justification at each step. Prove that the sum of any two rational numbers is a rational number. Give a justification at each step

  Demonstrate the class in a program that contains car object

Demonstrate the class in a program that contains a Car object, and then calls the accelerate method five times. After each call to the accelerate method.

  Write a script that inputs several lines of text

Write a script that inputs several lines of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text.

  Write a program to display a simplified bill

Write a program to display a simplified bill. The customer's name, the number of hours of labor, and cost of parts and supplies should be entered into the program via text boxes. When a button is clicked, the customer's name and the three costs sh..

  Write program to implement autocomplete for given set

CPS 350- Write a program to implement autocomplete for a given set of N terms, where a term is a query string and an associated nonnegative weight. That is, given a prefix, find all queries that start with the given prefix, in descending order of ..

  Write jquery selector to get all that contain the word hello

Write a jQuery selector to get all the that contain the word "hello." jQuery extends the CSS syntax for selectors. Explain what that means. How can we ensure jQuery loads, even if the CDN is down?

  Modify the given program to use a loop to output

This program outputs a downwards facing arrow composed of a rectangle and a right triangle. The arrow dimensions are defined by user specified arrow base height

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