Part 1: Create Car and Garage classes in accordance with the following specifications. I have provided the CarTester class as a test driver to test your Car and Garage classes. Do not change the CarTester class source code. Car Class Specifications: The Car class must be in a separate package from the CarTester class. The Car class will contain, at a minimum, the following information as constants (in Java use final to specify a constant): make model year fuel tank size fuel economy – fuel economy at best speed optimal speed – speed at which the car has the most efficient fuel economy You will need other fields besides those listed above. These other fields will not be constants. Some of the other fields: odometer trip odometer color fuel level The Car class will also need 2 constructors: Car() – a no argument constructor that initializes an instance using random values. Car(String, String, String, int, double, double, double) – accepts arguments to initialize the new Car object with make, model, color, year, tank size, fuel economy, and best speed. You should also initialize the two odometers and the fuel level with random values. The Car class must implement the following methods. package addFuelToTank(double): double (Note: This method needs to be public for the CarTester program and package for the CarGarageDriver program. The package access modifier is implemented by leaving the method’s access modifier blank. Package is used to restrict access to classes in the same package.) Adds fuel to the car's fuel tank Precondition: Car has a fuel tank Postcondition: Car's fuel tank may have added fuel Parameter available fuel to add to fuel tank returns: Negative number indicating the amount of fuel the tank will still take, Positive nonzero value of the amount of argument fuel not used, if 0 it just filled the tank public toString():String
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
I need this in Java please ASAP!
Part 1:
Create Car and Garage classes in accordance with the following specifications. I have provided
the CarTester class as a test driver to test your Car and Garage classes. Do not change the
CarTester class source code.
Car Class Specifications:
The Car class must be in a separate package from the CarTester class.
The Car class will contain, at a minimum, the following information as constants (in Java use
final to specify a constant):
make
model
year
fuel tank size
fuel economy – fuel economy at best speed
optimal speed – speed at which the car has the most efficient fuel economy
You will need other fields besides those listed above. These other fields will not be constants.
Some of the other fields:
odometer
trip odometer
color
fuel level
The Car class will also need 2 constructors:
Car() – a no argument constructor that initializes an instance using random values.
Car(String, String, String, int, double, double, double) – accepts arguments to initialize
the new Car object with make, model, color, year, tank size, fuel economy, and best
speed. You should also initialize the two odometers and the fuel level with random
values.
The Car class must implement the following methods.
package addFuelToTank(double): double (Note: This method needs to be public for the
CarTester program and package for the CarGarageDriver program. The package access modifier
is implemented by leaving the method’s access modifier blank. Package is used to restrict
access to classes in the same package.)
Adds fuel to the car's fuel tank
Precondition: Car has a fuel tank
Postcondition: Car's fuel tank may have added fuel
Parameter available fuel to add to fuel tank
returns: Negative number indicating the amount of fuel the tank will still take, Positive
nonzero value of the amount of argument fuel not used, if 0 it just filled the tank
public toString():String
Converts the Car object's state variables to a String representation
Precondition: All state variables are initialized
Postcondition: no change
Returns a string representation of state variables
public equals(Car):boolean
Checks to see if the calling Car and the argument Car have the same state
Precondition: Both the calling Car and argument Car are fully initialized
Postcondition: no change
parameter pCarObject
returns true if the calling Car and the argument Car have the same state values for year,
make, and model, else returns false
public driveCar():boolean
drives the Car a predefined distance and speed.
Precondition: Car's trip state variables have been initialized
Postcondition: Car's fuel is reduced proportional to the distance and speed driven or
depleted if the distance and speed are too great. Odometer and trip odometer are
updated with the miles traveled added. Car's trip state variables distance of travel and
speed of travel are set to zero.
Return: true if the car travels the distance with fuel remaining, false if the car runs out
of fuel
public getTripOdometer():double
gets trip odometer
Precondition: none
Postcondition: no change of state
Return: double value of trip odometer to nearest tenth of mile
public clearTripOdometer():void
sets trip odometer mileage to 0.0
Precondition: none
Postcondition: trip odometer set to 0.0
public getOdometer():double
gets odometer mileage
Precondition: none
Postcondition: no change to state
Return: double value of odometer to nearest tenth of mile
Trending now
This is a popular solution!
Step by step
Solved in 2 steps