Develop a simple RentalCarCompany program for a Rental Car

profileTopsolutions
 (Not rated)
 (Not rated)
Chat

Develop a simple RentalCarCompany program for a Rental Car Company, call it whatever you like. We will have two classes, a Car class and aRentalCarCompany class. The RentalCarCompany class will contain several Car objects stored in an array and will have several operations. We will also have a tester class to test the RentalCarCompany class.
Specific Requirements for theCar class:

Default constructor that sets all instance variables to default values.
A parameterizes constructor that takes in parameters to set the class's instance variables : String (the name of the car renter), int (the car number: a number used to identify each rental car the company owns), String (the car name or model), String (the car type, for example, compact or mid size), double (the car's rental rate), and an int (the number of days rented).
Accessor and mutator methods for all the instance variables (see UML Class diagram above)
toString() returns the car renter's name, the car number, name, type, number of doors (2 or 4), car rental rate, and number of days rented. This should all be nicely formatted with one attribute on each line using the '\n' escape character (see sample output below for an example).
The UML class diagram for the Car class looks like this:


Car

carRenter: String
carNum: int
carName: String
carType: String
rate: double
days: int
Car()
Car(String,int,String,String,int, double,int)
getCarRenter(): String
getCarNum(): int
getCarName(): String
getCarType(): String
getCarRate(): double
getNumOfDays(): int
setCarRenter(String)
setCarNum(int)
setCarName(String)
setCarType(String)
setCarRate(double)
setNumOfDays(int)
toString: String


Specific Requirements for the RentalCarCompany class:
Default constructor
Parameterized constructor that takes in the name of the Car Rental Company.
Instance variables include an array of Car objects called theCars to hold information about each car. A String representing the name of the company and a variable called rentCnt the indicates how may cars have been rented (car object actually stored in the array).
A Class constant called NUM_CARS is an int representing the size of the array. For this project, we will assume that the rental car company will not have more than 20 cars, so set the array size to 20.
Methods
Accessor and mutator methods for name instance variable
addReservation method
Adds a Car object to theCars array using the parameters to create a Car object.
An array needs to be created with a fixed size, however number of cars rented at any time may vary therefore to solve this problem we will use a partially filled array (See text for details on partially filled arrays) . The instance field calledrentCnt indicates the actual number of cars currently rented.
getTotalRentalSales - returns a double representing the total sales of all the cars in the array, the sale value formula is the car's (rate * days)
findReservation
Searches the array using a parameter that reprsents a car's carNum.
If the reservation is found, the findReservation method will print out the rental car's information using the car's toStringmethod. If not, the method prints out a message indicating that the reservation was not found.
toString - will print out the information for each rental car by calling the toString method for each Car object. (see sample run below)
The UML class diagram for the RentalCarCompany class looks like this:


RentalCarCompany
theCars: Car[]
name: String
rentCnt : int
NUM_CARS: int
RentalCarCompany()
RentalCarCompany(String)
getName():String
setName(String)
addReservation(String, int, String, String, double, int)
getTotalRentalSales(): double
findReservation(int)
toString(): String

Build a RentalCarTest class to test your application. It should verify the correct operation of the constructor and all public methods in theRentalCarCompany class. Remember to test the addReservation() method, which should add cars to the array, and the findReservation()method, which should be able to find a car in the array of objects if it exists. See the sample output below for a sample run of the test program.
Your source files must have Javadoc comments for each class, method and constructor, with relevant tags.

You should turn in the following files for this assignment:

Car.java
RentalCarCompany.java
RentalCarTest.java

    • 10 years ago
    Complete Solution A++
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      rentalcarcompany2.zip