Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write code underneath the 2 buttons as follows: Perform the following error chec

ID: 3577255 • Letter: W

Question

Write code underneath the 2 buttons as follows:

Perform the following error checking on user input when the "Calculate mpg" button is clicked.

If user enters 0 or negative values, display error message

If user enter non-numeric values, display error message

When the "Calculate mpg" button is clicked and user input is error free, calculate the miles per gallon based upon used input. Remember to convert string input to floats.

Display answer with mpg formatted to 1 or 2 decimal place.

Calculations must be made only if there are no errors in input.

When the "Exit" button is clicked, exit the program.

Testing & Sample output

Before testing the script, I created test Data sets. These are sets of test data whose output value has been calculated. When the script is run across these test values, the answers produced by the script should be the same as my calculated value.

Test Data Sets

Test Data Set #1

Test Data Set #2

Gallons

3

Miles Travelled

58

Calculated mpg

19.3

Gallons

3

Miles Travelled

100

Calculated mpg

33.3

Sample output

Sample output from my implementation is as follows:

Error condition

Error condition

Error!

mpg is not formatted to 2 decimal places

Correct Output

Test Data Set #1

Test Data Set #2

Gallons

3

Miles Travelled

58

Calculated mpg

19.3

Gallons

3

Miles Travelled

100

Calculated mpg

33.3

20 Maya I olappa 3. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry that let the user enter the number of gallons of gas the car holds, and the number of miles it can driven a full tank. When a Calculate MPG button is clicked, the program should display the number of miles that the car may be driven per gal- lon of gas. Use the following formula to calculate miles-per-gallon: MPG gallons miles Additional Specifications The program should display an error message when User inputs non-numeric values User enters a value that is equal to or less than 0

Explanation / Answer

import java.util.Scanner; public class wtrbll { public static void main(String[] args) { Scanner in = new Scanner (System.in); int previousmeter, presentmeter,amountdue; double firstltr, nextltr,lastltr, meterrent; System.out.print("Please Enter Previous Meter Reading - - - > " ); previousmeter = in.nextInt(); System.out.print("Please Enter Present Meter Reading - - - > " ); presentmeter = in.nextInt(); System.out.println("------------------------------Water Charge-----------------------------------"); System.out.println("__________________________Units_________________________________Amount Due"); System.out.println("Meter Rental"+meterrent); System.out.println("Present Reading "+presentmeter); System.out.println("Previous Reading "+previousmeter); System.out.println("Quantity Used "+(presentmeter - previousmeter)); if (firstltr =0 && = 10001 && 20001); else amountdue=lastltr*0.005; { } } System.out.println("Litres At 0.002 Cents "+ nextltr*0.002 +(firstltr*0.001)); System.out.println("Litres At 0.005 Cents "+ lastltr*0.005);
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote