Program 3 Instructions
User Manual:
Open the PDF directly: View PDF .
Page Count: 1
Download | |
Open PDF In Browser | View PDF |
Program 3 We will make some changes to our second program. If you recall Program #1 began with, A car's gas mileage or miles-per-gallon (MPG) can be calculated with the following Formula: MPG = Miles Driven / Gallons of gas used Then Program #2 added a class called Mileage with two private member variables called miles and gallons of type double. The class had four public methods: setMiles and setGallons used void return types; getMiles and getGallons used double return types. It had one more method called getMPG that performed the math calculation and returned the double mpg The MPGMain asked the user for the number of miles driven and the gallons of gas used. It called the Mileage class to calculate the car's MPG. Then the class returned the MPG to the MPGMain where it was called and displayed the value on the screen. (Formatted display and limited the miles-per-gallon to 2 decimal places) Program #3 Begin with Program #2 Solution file. You will need to add two more classes to the Java Project. One called Distance and one called Speed. Similar to Mileage, Distance will have two private member variables, speed and time (both doubles); Speed will have two private member variables distance and time (again both are doubles). They will need sets and gets (also called accessors and mutators). Distance should have one more method called getDistance that performs the math calculation and returns the double totalDistance. Speed should have one more method called getMPH that performs the math calculation and returns the double mph Add a menu like the following to MPGMain: Enter Enter Enter Enter 1 2 3 4 to to to to Determine Miles-per-Gallon Determine Distance Determine Miles-per-Hour Exit The program should switch on the user’s choice. The program should continue until the user enters 4. If the user enters a number greater than 4 or less than 1 the program should display an error message and prompt the user to reenter a number between 1 and 4. The program will continue to display the error message allowing the user to reenter their choice until they enter a number within the correct range. Each case in the switch statement should create an instance of the appropriate class (for example, case 1: Mileage, case 2: Distance, case 3: Speed), and set the variable values using the set methods of the class. Each case statement should also display the results of the appropriate mathematical calculations by calling the getMPG, getDistance, or getMPH methods. Attach the compressed folder containing the program files and folders you created. Submit it through Blackboard for grading.
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.5 Linearized : No Page Count : 1 Language : en-US Author : Business Division Creator : Microsoft® Word 2016 Create Date : 2016:10:05 13:38:29-05:00 Modify Date : 2016:10:05 13:38:29-05:00 Producer : Microsoft® Word 2016EXIF Metadata provided by EXIF.tools