Question: USING JAVA Implement a class Car, which contains the fields: 1.make, e.g. Ford, Subaru, Toyota ... 2.model, e.g., Escape, Outback, Camry ... 3.year 4.MPG miles

USING JAVA

Implement a class Car, which contains the fields:

1.make, e.g. Ford, Subaru, Toyota ...

2.model, e.g., Escape, Outback, Camry ...

3.year

4.MPG miles per gallon

5.milesDriven, the total number of miles ever driven in this car.

6.fuelCapacity in gallons, i.e., the size in gallons of the fuel tank.

7.fuelRemaining, which represents the amount of fuel remaining in the gas tank.

Implement at least the following methods within the Car class:

>a constructor, which initializes each of the fields

>fillTank(double g), which adds up to g gallons of gas to the fuel tank, but not more than the car's fuel capacity.

>drive(double m), which simulates driving m miles in the car, adding to the total number of miles driven, and reducing the amount of gas in the car according to this car's average MPG.

>toString( ), which returns a String representation of the car.

>getFuelRemaining( ), which returns the amount of fuel left in the tank

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!