(Solved) : Part Implement Additional Following Classes Part Following Code Rentalcontract Concrete Cl Q32005959 . . .
Part a:
Implement additional following classes as part of thefollowing code
RentalContract
This is a concrete class which defines the attributes: carid, customer name, driving license number,issue date (date of renting out), return date(expected/actual return date of the car that is rented out)
RentalManager:
This class defines the attributes:list of cars and list of rental contracts. This classalso defines methods to add/remove a car or arental contract to/from the respective lists. Use anArrayList class provided in java.utilpackage for creating a list of cars and rentalcontracts.
Note: This class can be utility class and static methods can beprovided.
Additional requirements:
Must draw the UML diagram before starting the actual programdevelopment.
UML Link: .
Member variables and member methods must have suitable accessmodifiers.
Implement only required setter and gettermethods for member attributes.
Provide any additional methods as required.
Override the clone() method for the classes Car,Smallcar, MidRangeCar and LargeCar.
Override the equals() method for the classes Car,Smallcar, MidRangeCar and LargeCar.
Override the toString() for all the classes using asuitable print format.
Make sure that clone(), equals(), andtoString() use the super class’ equivalentmethod.
The issue date and return date attributes inthe RentalContract class must be of typeLocalDate.
The concept of polymorphism must be used whereverapplicable.
Part b:
Develop the main program such that the Rent-a-Carmanager:
Can list all the cars available with all their details.
Can ask a customer to choose a car.
Can execute the rental contract i.e., create a rental contractand add it to the rental contract list.
Can calculate and display rental charges for a customerbased on license number.
Can cancel a contract, which involves displaying the completedetails of the customer (name and driving license number), detailsof the car rented out to the customer, and rental charges.
DRIVER:
package javaapplication1;
import java.ut
il.*;
/**
*
* @author b00071518
*/
public class JavaApplication1
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int choice;
int ID, regNum, modelNum, daysRent = 0, price = 0, safety,cargo;
String brand, bodyType, driveSystem;
boolean status;
System.out.println(“<< Rent
–
a
–
Car Management Company >>”);
System.out.println(“
1
–
Small car”);
System.out.println(“2
–
Midrange car”);
System.out.println(“3
–
Large car”);
System.out.print(“Please input your choice: “);
choice = scanner.nextInt();
if(choice == 1)
{
System.out.println(“________________________”);
System.out.println(“BMW
–
200 AED/day”);
System.out.println(“Mercedes
–
250 AED/day”);
System.out.println(“Toyota
–
100 AED/day”);
System.out.println(
“________________________”);
System.out.print(“Please input the car brand: “);
brand = scanner.next();
if(brand.equals(“BMW”)) price = 200;
else if(brand.equals(“Mercedes”)) price = 250;
else if(brand.equals(“Toyota”)) price = 100;
System.out.print(“Please input the car ID: “);
ID = scanner.nextInt();
System.out.print(“Please input the registration number: “);
re
gNum = scanner.nextInt();
System.out.print(“Please input the model number: “);
modelNum = scanner.nextInt();
System.out.print(“PLease input how many days to rent: “);
daysRent = scanner.nextInt();
System.out.print(“Please input the body type (hatchback, sedanor convertible): “);
bodyType = scanner.next();
SmallCar sCar = new SmallCar(ID, regNum, modelNum, daysRent,brand, false,
bodyType);
price = price * daysRent;
System.out.println(“Brand: ” + sCar.getBrand()
+ “
nID: ” + sCar.getID()
+ “
nRegistration Number: ” + sCar.getRegNum()
+ “
nModel
Number: ” + sCar.getModelNum()
+ “
nRental Days: ” + sCar.getDaysRented()
+ “
nBody Type: ” + bodyType
+ “
nTotal Cost = ” + price + “
n”);
}
else if(choice == 2)
{
System.out.println(“________________________”);
System.out.println(“BMW
–
300 AED/day”);
System.out.println(“Mercedes
–
400 AED/day”);
System.out.println(“Toyota
–
200 AED/day”);
System.out.
println(“________________________”);
System.out.print(“Please input the car brand: “);
brand = scanner.next();
if(brand.equals(“BMW”)) price = 300;
else if(brand.equals
(“Mercedes”)) price = 400;
else if(brand.equals(“Toyota”)) price = 200;
System.out.print(“Please input the car ID: “);
ID = scanner.nextInt();
System.out.print(“Please input the regi
stration number: “);
regNum = scanner.nextInt();
System.out.print(“Please input the model number: “);
modelNum = scanner.nextInt();
System.out.print(“Please input how many days to rent: “);
daysRent = scanner.nextInt();
System.out.print(“Please input the number of Airbags: “);
safety = scanner.nextInt();
System.out.print(“Do you want luxury options?
n1
–
yes.
n2
–
no.”);
int luxury = scanner.nextInt();
MidrangeCar mCar;
if (luxury == 1 )
mCar = new MidrangeCar(ID, regNum, modelNum, daysRent, brand,false, safety,
true);
else
mCar = new Midr
angeCar(ID, regNum, modelNum, daysRent, brand, false,safety,
false);
price = price * daysRent;
System.out.println(“Brand: ” + mCar.getBrand()
+ “
nID: ” + mCar.getID()
+ “
nReg
istration Number: ” + mCar.getRegNum()
+ “
nModel Number: ” + mCar.getModelNum()
+ “
nRental Days: ” + mCar.getDaysRented()
+ “
nSafety: ” + safety
+ “
nTotal Cost = ” + pr
ice + “
n”);
}
else if(choice == 3)
{
System.out.println(“________________________”);
System.out.println(“BMW
–
600 AED/day”);
System.out.println(“Mercedes
–
700 AED/day”);
System.out.println(“Toyota
–
500 AED/day”);
System.out.println(“________________________”);
System.out.print(“Please input the car brand: “);
brand = scanner.next();
if(brand.equals(“BMW”)) price
= 600;
else if(brand.equals(“Mercedes”))price = 700;
else if(brand.equals(“Toyota”)) price = 500;
System.out.print(“Please input the car ID: “);
ID = scanner.nextInt();
System.out.print(“Please input the registration number: “);
regNum = scanner.nextInt();
System.out.print(“Please input the model number: “);
modelNum = scanner.nextInt();
System.out.print(“Pleas
e input howe many days to rent: “);
daysRent = scanner.nextInt();
System.out.print(“Please input the driving system: “);
driveSystem = scanner.next();
System.out.print(“Please input
the passenger volume: “);
cargo = scanner.nextInt();
LargeCar lCar = new LargeCar(ID, regNum, modelNum, daysRent,brand, false,
driveSystem, cargo);
price = price * daysRent;
System.ou
t.println(“Brand: ” + lCar.getBrand()
+ “
nID: ” + lCar.getID()
+ “
nRegistration Number: ” + lCar.getRegNum()
+ “
nModel Number: ” + lCar.getModelNum()
+ “
nRental Days: “
+ lCar.getDaysRented()
+ “
nDrive System: ” + driveSystem
+ “
nPassenger Volume: ” + cargo
+ “
nTotal Cost = ” + price + “
n”);
}
else System.out.println(“Invalid inp
ut. Run again.”);
}
}
CAR CLASS:
abstract class Car
{
int ID, regNum, modelNum, daysRent;
String brand;
boolean status;
Car()
{
ID = 0;
regNum = 0;
modelNum = 0;
daysRent = 0;
brand
= “NULL”;
status = true;
}
Car(int ID, int regNum, int modelNUm, int daysRent, Stringbrand, boolean status)
{
this.ID = ID;
this.regNum = regNum;
this.modelNum = modelNUm;
this.daysRent = daysRent;
this.brand = brand;
this.status = status;
}
void setID(int x) { ID = x;}
int getID() { return ID; }
void setRegNum(int x) { regNum = x; }
int getRegNum() { return regNum; }
void setModelNum(
int x) { modelNum = x; }
int getModelNum() { return modelNum; }
void setDaysRented(int x) { daysRent = x; }
int getDaysRented() { return daysRent; }
void setBrand(String x) { brand = x; }
String getBrand() { return
brand; }
void setStatus(boolean x) { status = x; }
boolean getStatus() { return status; }
}
LARGECAR CLASS:
public class LargeCar extends Car
{
String driveSystem;
int
cargo
;
LargeCar()
{
super();
driveSystem = “NULL”;
cargo
= 0;
}
LargeCar(int ID, int regNum, int modelNum, int daysRent,
String brand, boolean status, String driveSystem,
int cargo)
{
super(ID, regNum, modelNum, daysRent,
brand, status);
this.driveSystem = driveSystem;
this.
cargo
= cargo;
}
}
MIDRANGECAR CLASS:
public class MidrangeCar extends Car
{
int safety;
boolean luxury;
MidrangeCar()
{
super();
safety = 0
;
luxury = false;
}
MidrangeCar(int ID, int regNum, int modelNum, int daysRent,
String brand, boolean status, int safety, boolean luxury)
{
super(ID, regNum, modelNum, daysRent, brand, status);
this.safety = safety;
this.luxury = luxury;
}
}
SMALLCAR CLASS:
public class SmallCar extends Car
{
String bodyType;
SmallCar()
{
super();
bodyType = “NULL”;
}
SmallCar(int ID, int regNum, int mo
delNum, int daysRent,
String brand, boolean status, String bodyType)
{
super(ID, regNum, modelNum, daysRent, brand, status);
this.bodyType = bodyType;
}
}
Expert Answer
Answer to Part Implement Additional Following Classes Part Following Code Rentalcontract Concrete Cl Q32005959 . . .
OR