0% found this document useful (0 votes)
8 views2 pages

OOP Inheritance Assignment

The document outlines a Java assignment focused on creating a Vehicle Rental Service using object-oriented programming principles, particularly inheritance. It details the design of a Vehicle class as a parent class with common attributes and methods, and three child classes (Car, Bike, Truck) that extend the Vehicle class with specific attributes and overridden methods. Additionally, it describes the VehicleRentalSystem class, which manages the fleet of vehicles and provides functionalities for renting, returning, and displaying vehicles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

OOP Inheritance Assignment

The document outlines a Java assignment focused on creating a Vehicle Rental Service using object-oriented programming principles, particularly inheritance. It details the design of a Vehicle class as a parent class with common attributes and methods, and three child classes (Car, Bike, Truck) that extend the Vehicle class with specific attributes and overridden methods. Additionally, it describes the VehicleRentalSystem class, which manages the fleet of vehicles and provides functionalities for renting, returning, and displaying vehicles.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Assignment: Object-Oriented Programming (OOP) Inheritance

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:

1. Vehicle Class (Parent Class):


 All vehicles share some basic attributes, so start by creating a base class called
Vehicle.
 Common attributes:
 String model: The model name of the vehicle.
 String registrationNumber: A unique registration number for the
vehicle.
 double pricePerDay: The rental price per day for the vehicle.
 boolean isAvailable: A flag indicating whether the vehicle is available
for rent.
 Common methods:
 void rentVehicle(): Marks the vehicle as rented (sets isAvailable to
false).
 void returnVehicle(): Marks the vehicle as returned (sets
isAvailable to true).
 String getVehicleDetails(): Returns a string containing the details of
the vehicle.
 double calculateRentalCost(int days): Calculates the total rental
cost based on the number of days rented.
2. Car Class (Child Class):

 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.

4. Truck Class (Child Class):

 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.

5. VehicleRentalSystem Class (Main Class):

 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.

You might also like