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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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

 

**Title: Understanding Fuel Usage Calculation in Cars**

**Functions Overview:**

1. **public getFuelLevel() : double**
   - **Purpose**: Retrieves the fuel level in gallons.
   - **Precondition**: Fuel level is initialized.
   - **Postcondition**: No change in state.
   - **Return**: Fuel level in gallons with decimal values.

2. **public getFuelTankSize() : double**
   - **Purpose**: Retrieves fuel tank size in gallons.
   - **Precondition**: Fuel level is initialized.
   - **Postcondition**: No change in state.
   - **Return**: Fuel tank level in gallons with decimal values.

3. **public setUpTrip(double, double) : void**
   - **Purpose**: Sets the initial speed of travel and the distance to travel at that speed.
   - **Precondition**: None.
   - **Postcondition**: Car’s state holds information on distance to travel and speed to travel.
   - **Parameters**: 
     - Average speed to be driven
     - Distance to drive

**Algorithm for Fuel Usage Calculation:**

Develop an algorithm that calculates the fuel used and the actual distance driven. Factors include whether the car is driven faster or slower than an optimal speed, which affects mileage using a formula or multiple formulas (as a piecewise function).

When a new Car object is instantiated:
- It is initialized with an optimal speed variable.
- Your algorithm should set limits on how many miles per gallon (MPG) your car will get (e.g., an arbitrary limit of 2 or 3 miles per gallon).

**Additional Methods and Fields:**

- Create a Car object such that:
  - The car’s odometer is set to a random number between 0.0 and 5.99.
  - The car’s trip odometer is set to 0.0.
  - Its best fuel economy (MPG) is set to a random number between 15.0 and 54.99.
  - Its optimal speed is a random number between 45.0 and 64.99.
  - Its fuel tank size is a random number between 8 and 34.9 gallons.

**Hint for Generating Random Values:**

- Use helper methods to generate these random values.
- Use `Math.random()` for generating numbers:
  - Generates a random double number (0.0 to less than
Transcribed Image Text:**Title: Understanding Fuel Usage Calculation in Cars** **Functions Overview:** 1. **public getFuelLevel() : double** - **Purpose**: Retrieves the fuel level in gallons. - **Precondition**: Fuel level is initialized. - **Postcondition**: No change in state. - **Return**: Fuel level in gallons with decimal values. 2. **public getFuelTankSize() : double** - **Purpose**: Retrieves fuel tank size in gallons. - **Precondition**: Fuel level is initialized. - **Postcondition**: No change in state. - **Return**: Fuel tank level in gallons with decimal values. 3. **public setUpTrip(double, double) : void** - **Purpose**: Sets the initial speed of travel and the distance to travel at that speed. - **Precondition**: None. - **Postcondition**: Car’s state holds information on distance to travel and speed to travel. - **Parameters**: - Average speed to be driven - Distance to drive **Algorithm for Fuel Usage Calculation:** Develop an algorithm that calculates the fuel used and the actual distance driven. Factors include whether the car is driven faster or slower than an optimal speed, which affects mileage using a formula or multiple formulas (as a piecewise function). When a new Car object is instantiated: - It is initialized with an optimal speed variable. - Your algorithm should set limits on how many miles per gallon (MPG) your car will get (e.g., an arbitrary limit of 2 or 3 miles per gallon). **Additional Methods and Fields:** - Create a Car object such that: - The car’s odometer is set to a random number between 0.0 and 5.99. - The car’s trip odometer is set to 0.0. - Its best fuel economy (MPG) is set to a random number between 15.0 and 54.99. - Its optimal speed is a random number between 45.0 and 64.99. - Its fuel tank size is a random number between 8 and 34.9 gallons. **Hint for Generating Random Values:** - Use helper methods to generate these random values. - Use `Math.random()` for generating numbers: - Generates a random double number (0.0 to less than
**Part 2:**

After you are comfortable with the Car class, create a Garage class to store Cars. The Garage object is an instantiation of a Garage class that contains “parking”, an array of the Car class. You must use a Car[] not an ArrayList<Car> for the “parking” in the garage. You will use Car objects to fill the garage. I will provide an algorithm for the CarGarageDriver class as a test driver to test your car and Garage classes.

The rules for the garage are:

- The size of the garage is specified by the user.
- The user may only use cars from the garage.
- A Car is removed from the Garage when a user retrieves a Car from the Garage.
- The Car is returned to the Garage after it is driven if it does not run out of fuel.
- The user interacts with the Car object after the Car object is retrieved from the garage.
- The program should not fail due to a user selection.
- A car may only be refueled while in the Garage.
- The user may select to drive any Car that is currently in the garage.
- The user is the only one that may request that a car be refueled (do not refuel a car automatically).
- After the user selects a Car, they set up the drive by entering in the average speed and the driving distance.
- Select the Car the method above.
- The driving distance is the round-trip distance from the garage and back again.
- The driver program is only allowed to use the Car’s public methods listed above, and those you create for the Garage class.
- The user drives the car by telling that car to drive. Again, you may use menus to offer options to the user. (See the attached example run of my CarGarageDriver implementation.)
Transcribed Image Text:**Part 2:** After you are comfortable with the Car class, create a Garage class to store Cars. The Garage object is an instantiation of a Garage class that contains “parking”, an array of the Car class. You must use a Car[] not an ArrayList<Car> for the “parking” in the garage. You will use Car objects to fill the garage. I will provide an algorithm for the CarGarageDriver class as a test driver to test your car and Garage classes. The rules for the garage are: - The size of the garage is specified by the user. - The user may only use cars from the garage. - A Car is removed from the Garage when a user retrieves a Car from the Garage. - The Car is returned to the Garage after it is driven if it does not run out of fuel. - The user interacts with the Car object after the Car object is retrieved from the garage. - The program should not fail due to a user selection. - A car may only be refueled while in the Garage. - The user may select to drive any Car that is currently in the garage. - The user is the only one that may request that a car be refueled (do not refuel a car automatically). - After the user selects a Car, they set up the drive by entering in the average speed and the driving distance. - Select the Car the method above. - The driving distance is the round-trip distance from the garage and back again. - The driver program is only allowed to use the Car’s public methods listed above, and those you create for the Garage class. - The user drives the car by telling that car to drive. Again, you may use menus to offer options to the user. (See the attached example run of my CarGarageDriver implementation.)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education