Implement a class Car, each of whose objects has a certain amount of gas in the gas tank, uses a specific amount of fuel per mile, and has a gas tank with a certain capacity. Provide a constructor...



Implement a class Car, each of whose objects has a certain amount of gas in the gas tank, uses a specific amount of fuel per mile, and has a gas tank with a certain capacity.


Provide a constructor that specifies the miles per gallon for the car. Define a method named drive that allows the car to be driven a certain distance and decrements the fuel supply appropriately. Also define a method named refuel that adds fuel to an existing Car object. Be sure to define appropriate accessor and mutator methods for the class.


Test your class using a program that instantiates two different cars, one with a fuel efficiency of 32 miles per gallon and a 12-gallon tank, and one with a fuel efficiency of 21 miles per gallon and a 22-gallon tank. Each car is driven 121 miles with 10 gallons of fuel. Compute the amount of fuel remaining in each car.



May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here