Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions