Question: Help with Java please: Create a new Class that is an Exception Call the base (super) constructor with the same message, but append -
Help with Java please:
- Create a new Class that "is an" Exception
- Call the base (super) constructor with the same message, but append " - my exception" to the text
- Create a main function in a driver class
- Inside a loop, call a function to prompt the user to input miles driven and gallons used
- If either number is negative, do not add the values to the totals
- If something other than an integer is entered, assume the user intended to display the output and exit the program.
- After each pass of the loop, display "------------", even after the user has exited by typing in a string
- Inside a loop, call a function to prompt the user to input miles driven and gallons used
- Display miles per gallon calculation
- This should be a separate function
Don't forget to consider the case when the very first value the user enters is a string
Sample
Enter miles driven on this tank: 527 Enter number of gallons: 23 ------------ Enter miles driven on this tank: 403 Enter number of gallons: 16 ------------ Enter miles driven on this tank: -200 Negative value detected - my exception ------------ Enter miles driven on this tank: 494 Enter number of gallons: 21 ------------ Enter miles driven on this tank: 475 Enter number of gallons: -12 Negative value detected - my exception ------------ Enter miles driven on this tank: 488 Enter number of gallons: foo ------------ Average miles per gallon: (527+403+494)/(23+16+21) = 23
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
