0% found this document useful (0 votes)
5 views16 pages

Programming Assignment Unit 6

The document outlines a vehicle management system designed in Java, focusing on the implementation of various interfaces for different vehicle types including cars, motorcycles, and trucks. It details the structure of interfaces and classes, including methods for managing vehicle attributes and user interactions. The main program facilitates vehicle creation, input validation, and displays vehicle details to the user.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views16 pages

Programming Assignment Unit 6

The document outlines a vehicle management system designed in Java, focusing on the implementation of various interfaces for different vehicle types including cars, motorcycles, and trucks. It details the structure of interfaces and classes, including methods for managing vehicle attributes and user interactions. The main program facilitates vehicle creation, input validation, and displays vehicle details to the user.

Uploaded by

nazilaramzi25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Designing a Vehicle Management System: Utilizing Interfaces in Java

CS 1102-01 Programming 1 - AY2025-T5

Programming Assignment Unit 6

Instructor: Salah Jabareen

July 27, 2025


Car Rental Agency System in Java

Code:

1. Vehicle Interface

2. CarVehicle Interface

3. MotorVehicle Interface
4. TruckVehicle Interface

5. Car Class
6. Motorcycle Class
7. Truck Class
8. Main Class Vehicle Information System
Screenshot of Code Output:

Vehicle Information System Documentation

1. Interface Definitions

Vehicle Interface

This is a general interface that defines common methods for all vehicles.

Methods:
 String getMake(): Returns the make (brand) of the vehicle.

 String getModel(): Returns the model of the vehicle.

 int getYearOfManufacture(): Returns the year of manufacture of the vehicle.

CarVehicle Interface

This interface extends the Vehicle interface with additional methods specific to cars.

Methods:

 void setNumberOfDoors(int doors): Sets the number of doors for the car.

 int getNumberOfDoors(): Retrieves the number of doors for the car.

 void setFuelType(String fuelType): Sets the fuel type used by the car (e.g., petrol, diesel,

electric).

 String getFuelType(): Retrieves the fuel type of the car.

MotorVehicle Interface

This interface defines methods specific to motorcycles.

Methods:

 void setNumberOfWheels(int wheels): Sets the number of wheels for the motorcycle.

 int getNumberOfWheels(): Retrieves the number of wheels of the motorcycle.

 void setType(String type): Sets the type of motorcycle (e.g., sport, cruiser, off-road).

 String getType(): Retrieves the motorcycle type.

TruckVehicle Interface

This interface defines methods specific to trucks.

Methods:

 void setCargoCapacity(double tons): Sets the cargo capacity of the truck in tons.
 double getCargoCapacity(): Retrieves the cargo capacity of the truck.

 void setTransmissionType(String transmission): Sets the transmission type (manual or

automatic).

 String getTransmissionType(): Retrieves the transmission type of the truck.

2. Class Implementations

Car Class

Implements the Vehicle and CarVehicle interfaces.

Fields:

 String make: Make (brand) of the car.

 String model: Model of the car.

 int yearOfManufacture: Year of manufacture.

 int numberOfDoors: Number of doors on the car.

 String fuelType: Type of fuel the car uses.

Key Methods:

getMake(), getModel(), getYearOfManufacture(): Retrieve general vehicle information.

setNumberOfDoors(), getNumberOfDoors(): Set and retrieve the number of doors.

setFuelType(), getFuelType(): Set and retrieve the fuel type.

Motorcycle Class

Implements the Vehicle and MotorVehicle interfaces.

Fields:

 String make: Make of the motorcycle.

 String model: Model of the motorcycle.

 int yearOfManufacture: Year of manufacture.


 int numberOfWheels: Number of wheels on the motorcycle.

 String type: Type of motorcycle (e.g., sport, cruiser, off-road).

Key Methods:

getMake(), getModel(), getYearOfManufacture(): Retrieve general vehicle information.

setNumberOfWheels(), getNumberOfWheels(): Set and retrieve the number of wheels.

setType(), getType(): Set and retrieve the type of motorcycle.

Truck Class

Implements the Vehicle and TruckVehicle interfaces.

Fields:

 String make: Make of the truck.

 String model: Model of the truck.

 int yearOfManufacture: Year of manufacture.

 double cargoCapacity: Cargo capacity of the truck in tons.

 String transmissionType: Transmission type (manual or automatic).

Key Methods:

getMake(), getModel(), getYearOfManufacture(): Retrieve general vehicle information.

setCargoCapacity(), getCargoCapacity(): Set and retrieve the cargo capacity.

setTransmissionType(), getTransmissionType(): Set and retrieve the transmission type.

3. Main Program: VehicleInformationSystem

This is the entry point of the program, handling user interaction.

Key Sections

Vehicle Creation Methods


 createCar(): Prompts the user for details related to a car (make, model, year, doors, and fuel

type), creates a Car object, and returns it.

 createMotorcycle(): Prompts the user for details related to a motorcycle (make, model, year,

wheels, and type), creates a Motorcycle object, and returns it.

 createTruck(): Prompts the user for details related to a truck (make, model, year, cargo

capacity, and transmission type), creates a Truck object, and returns it.

Input Validation and Exception Handling

 Uses try-catch blocks for validating user input to handle invalid entries (e.g., entering a string

instead of a number).

 getIntInput(): Ensures that only valid integers are entered for fields such as the year of

manufacture or number of doors.

 getDoubleInput(): Ensures that only valid decimal numbers are entered for cargo capacity.

 Catches InputMismatchException and re-prompts the user for valid input.

Display Methods

 displayCarDetails(Car car): Displays the car's details.

 displayMotorcycleDetails(Motorcycle motorcycle): Displays the motorcycle's details.

 displayTruckDetails(Truck truck): Displays the truck's details.

These methods use the getter methods from the respective classes to access and print the information

of each vehicle in a readable format.


References

Eck, D. J. (2022). Introduction to programming using java version 9, JavaFX

edition. Licensed under CC 4.0

Eck, D. J. (2019). Introduction to programming using Java, version 8.1. Hobart and William

Smith College. Retrieved, http://math.hws.edu/javanotes

You might also like