OOP Inheritance Assignment
OOP Inheritance Assignment
Imagine a Vehicle Rental Service that rents out different types of vehicles, such as cars, bikes,
and trucks. Each type of vehicle has common attributes (price, model, and registration number)
but also some unique characteristics.
Your task is to design a Java system to model this service using object-oriented programming
principles, specifically focusing on inheritance.
Requirements:
The Car class extends the Vehicle class and adds specific attributes and methods for
cars.
Additional attributes:
int numberOfSeats: The number of seats in the car.
boolean hasAirConditioning: Whether the car has air conditioning.
Additional methods:
String getVehicleDetails(): Override the method to include details
specific to cars (e.g., number of seats and air conditioning).
double calculateRentalCost(int days): Override this method to apply a
special rate if the car has air conditioning.
3. Bike Class (Child Class):
The Bike class extends the Vehicle class and adds specific attributes and methods
for bikes.
Additional attributes:
boolean isElectric: Whether the bike is electric.
String typeOfBike: Type of bike (e.g., mountain bike, road bike).
Additional methods:
String getVehicleDetails(): Override the method to include details
specific to bikes (e.g., type of bike and electric status).
double calculateRentalCost(int days): Override this method to apply a
discount for electric bikes.
The Truck class extends the Vehicle class and adds specific attributes and methods
for trucks.
Additional attributes:
double loadCapacity: The maximum load capacity of the truck in
kilograms.
boolean hasGPS: Whether the truck has GPS navigation.
Additional methods:
String getVehicleDetails(): Override the method to include details
specific to trucks (e.g., load capacity and GPS availability).
double calculateRentalCost(int days): Override this method to apply
an additional fee for trucks with GPS.
The VehicleRentalSystem class will manage the fleet of vehicles and allow users to
interact with the system.
Implement a list of vehicles (ArrayList<Vehicle>) and provide the following
functionality:
void addVehicle(Vehicle vehicle): Add a new vehicle to the fleet.
void rentVehicle(String registrationNumber, int days): Rent a
vehicle by its registration number for a specified number of days.
void returnVehicle(String registrationNumber): Return a rented
vehicle.
void displayAllVehicles(): Display details of all vehicles in the fleet,
including their availability and rental costs.
Vehicle findVehicle(String registrationNumber): Find and return a
vehicle by its registration number.