For this assignment you will design a set of classes that work together to simulate a cars fuel gauge and odometer. The classes you will design are:
The FuelGuage class: this class will simulate a fuel guage. Its responsibilities are: To know the cars current amount of fuel, in gallons. To report the cars 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 cars odometer. Its responsibilities are: To know the cars current mileage. To report the cars 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 FuelGuage objects current amount of fuel by 1 gallon for every 24 miles traveled. The cars fuel economy is 24 mpg.
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 cars current mileage and amount of fuel.
Reviews
There are no reviews yet.