Question: HELP Please. This is from Java How to Program Chapter 3 edition 11. The assignment is to have the user input number of trips. Has

HELP Please.

This is from Java How to Program Chapter 3 edition 11.

The assignment is to have the user input number of trips. Has to be between 1 and 13. This needs to be verified. User needs to input miles between 10 and 300 and this needs to be verified. User needs to input gallons. between 1 and 18 and this needs to be verified. Next for each trip, we must compute the MPG. All of this must be printed tabular. So, trips under trips, miles under miles, gallons under gallons and Mpg under Mpg for each trip. So, it will have the headings and then all the inputs with the calculated MPG for each trip. I have included the code that I have generated. I am coding Java in Netbeans.

package chapterthree; import java.util.Scanner; import java.text.DecimalFormat; /** * * @author 12183 */ public class ChapterThree {

/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in);// creates scanner //declares and intializes inputs DecimalFormat formatter = new DecimalFormat("00.000"); int trip = 0;//initialize int miles = 1;//initialize double gallons;//initalize double milesPerGallon = 0; while (trip >= 13){//repeat loop 13 times System.out.println("Enter number of trips (1 to 13): ");//prompt trip=input.nextInt();//input number of trips trip = trip + 1;//increment increased by 1 if (trip < 13) {//tests trip input System.out.println("Great Job. Thanks.");//success }// close if else{//test trip if (trip > 13){//tested of input System.out.println("Larger than 13. Try again");}//input to large }//close else System.out.print("Enter number of miles (10 to 300): ");//prompt miles=input.nextInt();//input miles if (miles < 10){//test miles input System.out.println("Number is to small. Try again.");//fail to small }//close if else{//other test if (miles > 300){//if input is to large {System.out.println("Number is to large. Try again.");//fail }// close println }//close if }//close else System.out.println("Please Enter Gallons (1 to 18: ");//prompy gallons = input.nextInt();//input gallons if (gallons < 18) {//test input System.out.println("Thanks.");//success }//clsoe if else {//test input if (gallons > 18){//number larger then needed System.out.println("Number is to large. Try again.");//output }//close if }// close else milesPerGallon = miles / gallons; System.out.println("Trips \tMiles \tGallons \tMPG"); System.out.println("-------------------------------"); System.out.println(trip + "\t"+ miles + "\t"+ gallons + "\t"+ milesPerGallon); ); }//close while System.exit(0); }//close main }//closes the class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!