Car Instrument Simulator For this assignment you will design a set of classes th
ID: 3869398 • Letter: C
Question
Car Instrument Simulator
For this assignment you will design a set of classes that work together to simulate a
car’s fuel gauge and odometer. The classes you will design are:
• The FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are
– To know the car’s current amount of fuel, in gallons.
– To report the car’s current amount of fuel, in gallons.
– To be able to increment the amount of fuel by 1 gallon. This simulates putting
fuel in the car. (The car can hold a maximum of 15 gallons.)
– To be able to decrement the amount of fuel by 1 gallon, if the amount of fuel is
greater than 0 gallons. This simulates burning fuel as the car runs.
• The Odometer Class: This class will simulate the car’s odometer. Its responsibilities
are:
– To know the car’s current mileage.
– To report the car’s current mileage
– To be able to increment the current mileage by 1 mile. The maximum mileage the
odometer can store is 999,999 miles. When this amount is exceeded, the odometer
resets the current mileage to 0.
– To be able to work with a FuelGauge object. It should decrease the FuelGauge
object’s current amount of fuel by 1 gallon for every 24 miles traveled. (The car’s
fuel economy is 24 miles per gallon.)
Demonstrate the classes by creating instances of each. Simulate filling the car up with
fuel, and then run a loop that increments the odometer until the car runs out of fuel.
During each loop iteration, print the car’s current mileage and amount of fuel.
Display a menu like this:
1) Add Fuel
2) Drive
3) Display status
4) Exit
When you select Option 1:
How many gallons do you want to add? (don't need input validation)
return to main menu
When you select Option 2:
How many miles do you want to drive? (don't need input validation)
--Drive - check to see if fuel tank is empty before reaching destination, if so, ask how many more gallons they want to add to the tank. Continue driving until either tank is empty (add more gas) or until destination is reached.
Return to main menu and user can select to drive again or add more fuel. Or option 3 to display current mileage and fuel level. Option 4 to Exit program.
Explanation / Answer
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chegg.july;
/**
*
* @author Sam
*/
class FuelGuage {
static int fuelAmount;
public static void addFuel() {
if (fuelAmount < 15)
fuelAmount ++;
}
public static int getFuelAmount() {
return fuelAmount;
}
}
class Mileage {
static int currentMileage;
static private int fuelMileage;
public static int getCurrentMileage() {
return currentMileage;
}
public static void addMileage() {
currentMileage++;
fuelMileage ++;
if (fuelMileage == 24){
FuelGuage.fuelAmount--;
fuelMileage = 0;
}
if (currentMileage == 1000000)
currentMileage = 0;
}
}
Do you need the main function??
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.