Part 1: Create Car and Garage dasses in accordance with the following specifications. I have provided the CarTester class as a test driver to test your Car and Garage dasses. Do not change the CarTester dass source code. Car Class Specifications: The Car dass must be in aseparate package from the CarTester class. The Car dass will contain, at a minimum, the following information as constants (in Java use final to specify a constant): make • model • year fuel tanks ize 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 a dameter color fuel level The Car dass 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, tanksize, fuel economy, and best speed. You should ato initialize the two odometers and the fuel level with random values. The Car dass must implement the following methods. package addFuelToTank(double): double (Note: This methad needs to be public for the CarTester program and package for the CarGarage Driver program. The package access modifier i implemented by leaving the methods 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 Pastcondition: Car's fueltank may have added fuel Parameter available fuel to add to fuel tank

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

public getFuelLevel():double
 retrieves fuel level in gallons
 Precondition: fuel level is initialized
 Postcondition: no change in state
 Return: fuel level in gallons with decimal values
public getFuelTankSize():double
 retrieves fuel level in gallons
 Precondition: fuel level is initialized
 Postcondition: no change is state
 Return: fuel level in gallons with decimal values
public setUpTrip(double, double): void
 Car's state is set to hold the speed of travel and 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
Develop and use an algorithm that calculates the amount of fuel used and the actual distance
driven in the drive() method. The algorithm must use a formula or multiple formulas ( as a
piecewise function) that gives proportionately poorer mileage when the Car is driven faster or
slower than its optimal speed. When a new Car object is instantiated, it is initialized with an
optimal speed variable. Your fuel usage algorithm should set limits on how poor of MPG your
car will get, i.e. set an arbitrary limit of 2 or 3 miles per gallon.
You may add other methods and fields as needed.
When a new Car object is created,
 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 set to a random number between 45.0 and 64.99,
 and its fuel tank size is set to a random number between 8 and 34.99 gallons.
Hint: Use “helper” methods to generate these random values.
 Use Math.random( ) to generate your random numbers. Remember Math.random( )
generates a random double number value from 0.0 to but not including 1.0.
o So, to get a random number between 0.0 and 99.99 you must multiply the result
of Math.random( ) by 100.
o To get a random number between 5 and 15(excluding 15), subtract 5 from 15 to
get 10, multiply Math.random() by 10 then add 5.
o Example: If Math.random( ) produced 0.4584, multiplying it by 10 would produce
4.584. Then adding 5 would produce 9.584, which is a value between 5 and 15.

 

Since the new class Car inherits the .equals() and .toString() methods from the Java Object class,
you will need to overload the .equals( ) method and override the .toString( ) method.
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 gets a Car, they set up the drive by entering in the average speed and the
driving distance.
See the Car methods 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.)

## Part 1: Car and Garage Classes

### Introduction
Create Car and Garage classes based on the specifications listed below. The CarTester class is provided to test your Car and Garage classes. Do not modify the CarTester class source code.

### Car Class Specifications
- **Separation:** The Car class should be in a separate package from the CarTester class.
- **Constants:** The Car class should include the following constants:
  - Make
  - Model
  - Year
  - Fuel tank size
  - Fuel economy (at best speed)
  - Optimal speed (for best fuel economy)

### Additional Fields
You will also need to define additional fields which are not constants:
- Odometer
- Trip odometer
- Color
- Fuel level

### Constructors
The Car class should have two constructors:
1. **Default Constructor (Car()):** Initializes an instance using random values.
2. **Parameterized Constructor (Car(String, String, int, double, double, double)):** Accepts arguments to initialize:
   - Make
   - Model
   - Color
   - Year
   - Tank size
   - Fuel economy
   - Best speed

In both constructors, initialize the odometers and the fuel level with random values.

### Methods
The Car class must implement the following methods:
- **packageAddFuelToTank(double):** 
  - **Return Type:** double
  - **Note:** This method needs to be public for the CarTester program and package-private for the CarGarageDriver program. This is achieved by omitting the method’s access modifier (package access).
  - **Purpose:** Adds fuel to the car’s fuel tank.
  - **Precondition:** Car’s fuel tank may have added fuel.
  - **Postcondition:** Car’s fuel level is updated.
  - **Parameter:** The amount of fuel to add.

### Summary
This document details the requirements for implementing the Car class, including constructors and essential methods, to be used in conjunction with the CarTester class. Ensure your Car class meets these specifications to facilitate proper testing and functionality.
Transcribed Image Text:## Part 1: Car and Garage Classes ### Introduction Create Car and Garage classes based on the specifications listed below. The CarTester class is provided to test your Car and Garage classes. Do not modify the CarTester class source code. ### Car Class Specifications - **Separation:** The Car class should be in a separate package from the CarTester class. - **Constants:** The Car class should include the following constants: - Make - Model - Year - Fuel tank size - Fuel economy (at best speed) - Optimal speed (for best fuel economy) ### Additional Fields You will also need to define additional fields which are not constants: - Odometer - Trip odometer - Color - Fuel level ### Constructors The Car class should have two constructors: 1. **Default Constructor (Car()):** Initializes an instance using random values. 2. **Parameterized Constructor (Car(String, String, int, double, double, double)):** Accepts arguments to initialize: - Make - Model - Color - Year - Tank size - Fuel economy - Best speed In both constructors, initialize the odometers and the fuel level with random values. ### Methods The Car class must implement the following methods: - **packageAddFuelToTank(double):** - **Return Type:** double - **Note:** This method needs to be public for the CarTester program and package-private for the CarGarageDriver program. This is achieved by omitting the method’s access modifier (package access). - **Purpose:** Adds fuel to the car’s fuel tank. - **Precondition:** Car’s fuel tank may have added fuel. - **Postcondition:** Car’s fuel level is updated. - **Parameter:** The amount of fuel to add. ### Summary This document details the requirements for implementing the Car class, including constructors and essential methods, to be used in conjunction with the CarTester class. Ensure your Car class meets these specifications to facilitate proper testing and functionality.
**Car Class Methods Overview**

- **fillTank():double**
  - **Returns:** Negative number (amount of fuel the tank will still take) or positive number (amount of unused fuel).
  - **Precondition:** Car object's state variables are initialized.
  - **Postcondition:** No change.

- **toString():String**
  - Converts Car object's state variables to a String.
  - **Precondition:** All state variables are initialized.
  - **Postcondition:** No change.
  - **Returns:** String representation of state variables.

- **equals(Car):boolean**
  - Checks if the calling Car and the argument Car have the same state.
  - **Precondition:** Both Cars are initialized.
  - **Postcondition:** No change.
  - **Parameter:** Car object.
  - **Returns:** True if the Cars have the same state values for year, make, and model; otherwise, false.

- **driveCar():boolean**
  - Drives the Car a predefined distance and speed.
  - **Precondition:** Car's state variables are initialized.
  - **Postcondition:** Car's fuel is reduced; odometer and trip odometer are updated. Car's trip variables are reset if necessary.
  - **Returns:** True if the Car travels the distance with fuel remaining; false if it runs out.

- **getTripOdometer():double**
  - Retrieves trip odometer value.
  - **Precondition:** None.
  - **Postcondition:** No change of state.
  - **Returns:** Trip odometer value to the nearest tenth of a mile.

- **clearTripOdometer():void**
  - Sets trip odometer mileage to 0.0.
  - **Precondition:** None.
  - **Postcondition:** Trip odometer set to 0.0.

- **getOdometer():double**
  - Retrieves odometer mileage.
  - **Precondition:** Car must be in running state.
  - **Postcondition:** No change of state.
  - **Returns:** Odometer value to the nearest tenth of a mile.
Transcribed Image Text:**Car Class Methods Overview** - **fillTank():double** - **Returns:** Negative number (amount of fuel the tank will still take) or positive number (amount of unused fuel). - **Precondition:** Car object's state variables are initialized. - **Postcondition:** No change. - **toString():String** - Converts Car object's state variables to a String. - **Precondition:** All state variables are initialized. - **Postcondition:** No change. - **Returns:** String representation of state variables. - **equals(Car):boolean** - Checks if the calling Car and the argument Car have the same state. - **Precondition:** Both Cars are initialized. - **Postcondition:** No change. - **Parameter:** Car object. - **Returns:** True if the Cars have the same state values for year, make, and model; otherwise, false. - **driveCar():boolean** - Drives the Car a predefined distance and speed. - **Precondition:** Car's state variables are initialized. - **Postcondition:** Car's fuel is reduced; odometer and trip odometer are updated. Car's trip variables are reset if necessary. - **Returns:** True if the Car travels the distance with fuel remaining; false if it runs out. - **getTripOdometer():double** - Retrieves trip odometer value. - **Precondition:** None. - **Postcondition:** No change of state. - **Returns:** Trip odometer value to the nearest tenth of a mile. - **clearTripOdometer():void** - Sets trip odometer mileage to 0.0. - **Precondition:** None. - **Postcondition:** Trip odometer set to 0.0. - **getOdometer():double** - Retrieves odometer mileage. - **Precondition:** Car must be in running state. - **Postcondition:** No change of state. - **Returns:** Odometer value to the nearest tenth of a mile.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY