Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

public class RentalContract {

Vehicle[] vehicle;
private int numOfv;

public boolean addVehicle(Vehicle v ) {


if (numOfv < vehicle.length )
{if (v instanceof Car)
vehicle[numOfv++] = new Car (v.getId(), v.getMake(),v.getModel(),
v.getRentalRate(),((Car)(v)).getbodyType(),((Car)(v)).getNumDoors());
else
if (v instanceof Bike)
vehicle[numOfv++] = new Bike (v.getId(),
v.getMake(),v.getModel(), v.getRentalRate(),((Bike))(v)).getbikeType(),((Bike)
(v)).getSize());
return true;
}

return false;

public boolean removeVehicle(String id) {


int index = searchVehicle(id);
if (index != -1) {

vehicle[index] = vehicle[numOfv - 1];


vehicle[numOfv - 1] = null;
numOfv--;
return true;
}

return false;
}

public int searchVehicle(String id) {


for (int i = 0; i < numOfv; i++)
if (vehicle[i].getId().equals(id))
return i;
return -1;
}

}
//////////////////////////

public class Payment {


private double amount;
private String paymentDate;
private String paymentMethod;
public Payment(double amount, String paymentDate, String paymentMethod) {
this.amount = amount;
this.paymentDate = paymentDate;
this.paymentMethod = paymentMethod;
}

public boolean isPaid() {


return false;
}

public String toString() {

return "Payment [amount=" + amount + ", paymentDate=" + paymentDate + ",


paymentMethod=" + paymentMethod
+ "]\n";
}

}
////////////////////
public abstract class Car extends Vehicle {

private String bodyType;


private String numOfDoors;
private boolean isReserved;
private double baseRate;

public Car(String vehicleID, String make, String model, double rentalRate, String
type, String numOfDoors) {
super(vehicleID, make, model, rentalRate);
bodyType = type;
this.numOfDoors = numOfDoors;
}

public double calculateRentalCost(int days) {


double rentalCost = getRentalRate() * days;
if (days >= 7 && days <= 30) {
rentalCost *= 0.95;
} else
rentalCost *= 0.9;
rentalCost *= 1.05;
return rentalCost;
}

public boolean bookVehicle() {


if (isReserved) {
System.out.println("Car is already reserved.");
return false;
} else {
isReserved = true;
System.out.println("Done!");
return true;
}
}

public String toString() {


return super.toString() + ", Body Type: " + bodyType + ", Number of Doors: "
+ numOfDoors;
}

public String getBodyType() {


return bodyType;
}

public String getNumOfDoors() {


return numOfDoors;
}

}
//////////////////////
public class Bike extends Vehicle {

private String bikeType;


private String size;
private boolean isReserved;

public Bike(String vehicleID, String make, String model, double rentalRate, String
type, String size) {
super(vehicleID, make, model, rentalRate);
bikeType = type;
this.size = size;
}

public double calculateRentalCost(int days) {


double rentalCost = getRentalRate() * days;
if (days >= 7 && days <= 30) {
rentalCost *= 0.95;
} else
rentalCost *= 0.9;
rentalCost *= 1.05;
return rentalCost;
}

public boolean bookVehicle() {


if (isReserved) {
System.out.println("Bike is already reserved.");
return false;
} else {
isReserved = true;
System.out.println("Done!");
return true;
}
}

public String toString() {


return super.toString() + ", Type: " + bikeType + ", Size: " + size;
}

public String getBikeType() {


return bikeType;
}

public String getSize() {


return size;
}

You might also like