Question: In this exercise, you will be developing simple operations of car rental agencies to mange their inventory and the daily operations like rent and return
-
In this exercise, you will be developing simple operations of car rental agencies to mange their inventory and the daily operations like rent and return cars.
-
You will be creating two classes and one interface. The requirements of these classes and the interface are described by the give UML class diagram below.
-
Demo and add it into your project to test your application.
-
Do not forget to add proper comments to make your program self-documenting.
-
Specific requirements are given in the following subsections.
3.3.1 Creating the Car Class
-
Using IntelliJ IDE create a new Java project called CarRental. In this project, create an interface called Comparable to define the three methods shown in the UML diagram above.
-
To model the cars, you will create a new class, that implements Comparable interface, called Car. The constructor of this class takes four parameters and uses them to set values to their corresponding class fields. It also sets the value false to the rented field.
-
The setVIN() method assign the passed value to the VIN identification number (VIN) is a unique identifying code for a car.
-
The setSize() method assign the passed values of door and seat to the noOfDoors and noOfSeats correspondingly. Similarly, the setLuggage() method assign the passed values of suitcase and bag to the noOfSuitcases and noOfBags correspondingly.
-
The setRented() method uses the passed boolean value of status to assign the rented field of the class.
-
The getCarInfo() method returns a string that includes
the format,
, the angle brackets are not included. -
Since Car class implements Comparable, you must provide complete implementations for the three
methods in the Comparable interface. Consider the following requirements:
Abdelkader Ouda page 3 Winter 2021
SE 2203b
Software Design Laboratory 1
o
o o
isSameCar() method returns true if the value of the instance field VIN is equal to the passed VIN value, or false otherwise.
isRented() method returns the value of rented field. getCategory() method returns the category of the car based on the values of the fields noOfDoors, noOfSeats, noOfSuitcases, noOfBags and according the below table.
Category noOfDoors noOfSeats noOfSuitcases noOfBags Economy 4 5 1 1 Compact 4 5 1 2 Mid-size(Standard) 4 5 2 1 Full-size(Premium) 4 5 2 2 Convertible 2 4 1 1
8. The toString method needs to be implemented such that the output of the main program should be exactly as shown in Section 3.3.3 below.
3.3.2 Creating the CarRentalAgent Class
-
To model the operations of car rental company, you will create a new class called CarRentalAgent, as described in the diagram. The constructor of this class takes two parameters and uses them to set values to the companyName and address fields.
-
One of the nice things about Java is that it has many libraries and pre-defined data structures that you can simply use without have to write your own from scratch. Feel free to use a java.util.ArrayList to keep track of the car inventory, and define the carInventory field as an ArrayList of type Car.
-
The addInventory() method stores the passed car object into the carInventory collection only if there is no such car in the inventory (use isSameCar() method) and returns true, otherwise it returns false without adding the car.
-
The rentCar() method simulates the car renting process by changing the value of the rented field to true if the passed car is currently available (not rented) and returns true, otherwise it returns false.
-
The returnCar() method simulates the return process. It is changing the value of the rented field to false if the pass s true. Otherwise it returns false.
9. The printInventory() method should be able to print out a list of available cars. The list should be formatted exactly as it is shown in the main program execution described in Section 3.3.3 below.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
