Question: Submit Filename: DrivingCost.java (10th Edition Page 74 2.23) From Page 74 (Cost of driving)Write a program that prompts the user to enter driving distance, miles

Submit Filename: DrivingCost.java (10th Edition Page 74 2.23)

From Page 74 "(Cost of driving)Write a program that prompts the user to enter driving distance, miles per gallon and price per gallon, display the total cost of the trip".

Sample Run (user enters 900.5, 25.5 and 3.55)...

Enter the driving distance: 900.5 Enter miles per gallon: 25.5 Enter price per gallon: 3.55 The cost of driving is $125.36

Second Sample Run (user enters 1000.55 24 1.567 all on one line)

run: Enter the driving distance: 1000.55 24 1.567 Enter miles per gallon: Enter price per gallon: The cost of driving is $65.33 BUILD SUCCESSFUL (total time: 18 seconds)

Third Same Run Scanner Input set to new Scanner( "100 25.5 2.34");

run: Enter the driving distance: Enter miles per gallon: Enter price per gallon: The cost of driving is $9.18 BUILD SUCCESSFUL (total time: 0 seconds)

Hint

Use formatter for output, we want only two decimal point precision and comma every third digit left of decimal point. Output code is...

System.out.format( "... driving is $%,.2f ", cost );

Consistency Notes:

  1. Whenever we have a prompt it ends in : colon space, you have a space after the colon no space before colon.
  2. We don't end prompts with a newline, but in the first test case the user is entering numbers for each prompt.
  3. Unless otherwise specfied all input is free form format, that is white space delimited data, just ust nextDouble( );.
  4. Whenever we have calculations that are mixed types (i.e., float, int and/or double), declarations and calculations will be type double. Note in java.lang.Math almost all methods return and deal only with type double.
  5. Almost all double output uses format specifier ,.2f, or $%,.02f for Currency. Note , comma adds a comma every third digit, . dot represents precision, %.02f means fill missing output right of decimal point with Zeros.

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!