Question
Java Programming Problem Description For this assignment, you will design a set of classes that work together to simulate a cars fuel gauge and odometer.
Java Programming
Problem Description
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 as follows:
The FuelGauge Class. This class simulates a fuel gauge. It’s 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.
FuelGauge
+MAX_GALLONS=15:int
-gallons:int
+FuelGauge(g:int)
+getGallons():int
+incrementGallons():void
+decrementGallons():void
The Odometer Class. This class simulates the car’s odometer. It’s 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 FuelGuage 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.)
Odometer
+MAX_MILEAGE:int=999999
+MPG:int=24
-mileage:int
-setPoint:int
-fuelGauge:FuelGauge
+Odometer(m:int
fg:FuelGauge)
+getMileage():int
+incrementMileage()void
FuelGauge
+MAX_GALLONS=15 int
-gallons:int
+FuelGauge()
+FuelGauge(g:int)
+getGallons():int
+incrementGallons()void
+decrementGallons()void
Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, 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.
Step by Step Solution
3.46 Rating (156 Votes )
There are 3 Steps involved in it
Step: 1
The FuelGauge Class This class simulates a fuel gauge public class FuelGauge final int MAXGALLONS 15 ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started