Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions