Java Programming Assignment
Java Programming Assignment
Context: You are tasked with developing a software application for a car rental
agency. The application needs to handle different types of vehicles, including cars,
motorcycles, and trucks. To enforce a common behavior and ensure consistency
among these vehicle types, you decide to utilize interfaces. Additionally, you want to
incorporate various small modules into the question to make it engaging and
interactive for the developers.
Task:
1.
2.
1. Create an interface named Vehicle that includes methods for retrieving the
vehicle's make, model, and year of manufacture.
3.
4.
1. Create an interface named CarVehicle with methods for setting and retrieving
the number of doors and the fuel type (petrol, diesel, or electric).
2. Develop a class named Car that implements both Vehicle and CarVehicle
interfaces.
5.
6.
7.
8.
9.
10.
1. Develop a main program that allows the user to create objects of different vehicle
types, provide relevant information, and display the details of each vehicle.
Assessment Criteria:
1.
Interface Design:
2.
1. The Vehicle interface provides a contract specifying the methods for retrieving
vehicle details, ensuring a consistent structure for different vehicle types.
3.
Class Implementation:
4.
1. The Car, Motorcycle, and Truck classes translate the interface specifications
into concrete implementations, enabling the storage and retrieval of specific
attributes and behaviors.
5.
6.
1. The main program allows users to interactively create, input, and display details of
various vehicle objects, providing a comprehensive interface for managing and
accessing vehicle information.
7.
Code Quality:
8.
1. The code should emphasize readability, maintainability, and adherence to best
practices, ensuring a clean and well-structured codebase that promotes efficient
development and future scalability.
9.
Error Handling:
10.
11.
Documentation:
12.
Instructions:
// CarVehicle Interface
public interface CarVehicle {
void setNumberOfDoors(int doors);
int getNumberOfDoors();
void setFuelType(String fuelType);
String getFuelType();
}
// Car Class
public class Car implements Vehicle, CarVehicle {
private String make;
private String model;
private int yearOfManufacture;
private int numberOfDoors;
private String fuelType;
// MotorVehicle Interface
public interface MotorVehicle {
void setNumberOfWheels(int wheels);
int getNumberOfWheels();
void setType(String type);
String getType();
}
// Motorcycle Class
public class Motorcycle implements Vehicle, MotorVehicle {
private String make;
private String model;
private int yearOfManufacture;
private int numberOfWheels;
private String type;
// TruckVehicle Interface
public interface TruckVehicle {
void setCargoCapacity(double capacity);
double getCargoCapacity();
void setTransmissionType(String transmission);
String getTransmissionType();
}
// Truck Class
public class Truck implements Vehicle, TruckVehicle {
private String make;
private String model;
private int yearOfManufacture;
private double cargoCapacity;
private String transmissionType;
// Main Program
public class VehicleInformationSystem {
public static void main(String[] args) {
// Code to create and manage different vehicle objects
// ...
}
}