Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program that will calculate the number of miles per gallon and the number of kilometers per liter given gallons used and starting

Write a java program that will calculate the number of miles per gallon and the number of kilometers per liter given gallons used and starting and ending odometer readings. The user is also given the option to enter additional mileage calculations. Required algorithm to follow: o Do From the user, get the number of gallons used (could contain a decimal point). If the number of gallons used is positive (greater than 0), then Get the starting and ending odometer readings (integers) If the ending odometer reading is greater than the starting odometer reading o Compute and display the miles per gallon and liters per kilometer to exactly 4 digits of precision Else o Display the error message shown in the sample run Else Display the error message shown in the sample run. Prompt the user if they would like to calculate more mileage. Retrieve their choice and then display at least 5 equals symbols or asterisks. o While (their choice to calculate more mileage is Y or y) Note the structure presented above. Follow this structure in your program. Match the exact output shown below. Note that in the sample run there is a blank line between the input and the displayed computations when all input is valid. There is another blank line before the prompt to calculate more mileage. After the user enters their choice, a sequence of at least 5 equals symbols is displayed (will be the last line of your loop body). Use the following assumptions (constants) for metric conversion. Remember to create named constants rather than hard-code in the literal numbers. o 1.60934 kilometers per mile o 3.78541 liters per gallon) Follow all coding style guidelines presented thus far. Remember to make paragraphs of code preceded by a comment.

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

Students also viewed these Databases questions

Question

Distinguish between formal and informal reports.

Answered: 1 week ago