Meraj 69509050a7 Merge pull request 'develop' (#1) from develop into master
Great job completing the workshop!(100/120)
2026-05-19 16:16:25 +00:00
2026-04-24 21:23:02 +03:30
2026-04-24 21:23:02 +03:30
2026-04-24 21:23:02 +03:30
2026-04-25 10:19:32 +03:30

Workshop - Vehicle Management System

A simple hierarchy to learn OOP concepts like Interfaces, Inheritance, Polymorphism, and Abstraction.

Overview

This project simulates a vehicle management system using Object-Oriented Programming (OOP) principles. It demonstrates how real-world entities (like different types of cars) can be represented as classes, with shared characteristics and behaviors defined through interfaces, abstract classes, and inheritance.

Class Hierarchy

The project consists of the following classes and interfaces:

  1. Vehicle (Abstract Class): The base abstract class representing the core properties of any vehicle.
  2. Serviceable (Interface): An interface defining the contract for vehicles that require maintenance and servicing.
  3. Car (Abstract Class): A subclass of Vehicle that implements the Serviceable interface, representing common behaviors of cars.
  4. GasCar (Class): A concrete subclass of Car representing gasoline-powered vehicles.
  5. ElectricCar (Class): A concrete subclass of Car representing battery-powered electric vehicles.
  6. SportsCar (Class): A subclass of GasCar representing high-performance sports cars.
  7. VehicleInspector (Class): A utility class designed to inspect vehicles and demonstrate polymorphism and type-checking.

Class Diagram

       +-------------------+               +-------------------+
       |      Vehicle      |               |    Serviceable    |
       | (Abstract Class)  |               |    (Interface)    |
       +-------------------+               +-------------------+
                 ^                                   ^
                 | extends                           | implements
                 |                                   |
                 +-----------------------------------+
                                   |
                         +-------------------+
                         |        Car        |
                         | (Abstract Class)  |
                         +-------------------+
                                   ^
                                   | extends
                 +-----------------+-----------------+
                 |                                   |
       +-------------------+               +-------------------+
       |      GasCar       |               |    ElectricCar    |
       |      (Class)      |               |      (Class)      |
       +-------------------+               +-------------------+
         ^               ^                                   ^
         | extends       | implements                        | implements
         |               |                                   |
+-------------------+  +-------------------+       +-------------------+
|     SportsCar     |  |    Refuelable     |       |    Chargeable     |
|      (Class)      |  |    (Interface)    |       |    (Interface)    |
+-------------------+  +-------------------+       +-------------------+

What should you do?


Your task is to complete the implementation of the classes by finding the TODO comments in the codebase and fixing them:

1. Vehicle Class

  • Generate getters for all fields
  • Implement the addMileage(double km) method with negative value validation
  • Define abstract method getEnergyType()

2. Car Class

  • Complete the constructor using super
  • Override the getEnergyType()
  • Override the showDetails()
  • Implement needsService(Vehicle v) and performService() from the Serviceable interface

3. GasCar Class

  • Override getEnergyType()
  • Implement refuel(double amount) with validation
  • Override showDetails()
  • Override Serviceable.java methods

4. ElectricCar Class

  • Override getEnergyType()
  • Implement charge(double amount) with validation
  • Override showDetails()
  • Override Serviceable.java methods

5. SportsCar Class

  • Override showDetails to include specific Sports Car feature alongside the base class details
  • Override Serviceable.java methods

6. VehicleInspector Class

  • Complete the inspect(Vehicle v) method using instanceof

Main Class

  • Create at least 3 Vehicles

Example :

        ElectricCar tesla = new ElectricCar(
                "Tesla", "Model S", 2022, 1000,
                100, 550, 50   // batteryCapacity, range
        );

        GasCar toyota = new GasCar(
                "Toyota", "Corolla", 2018, 85000,
                5, 50, "Petrol"   // seats, fuelCapacity, fuelType
        );

        SportsCar ferrari = new SportsCar(
                "Ferrari", "F8 Tributo", 2021, 12000,
                2, 3.9, "oil", 710   // seats, engineSize, horsepower
        );
  • Create an array of all vehicles
  • Show basic info of each vehicle
  • Inspect each vehicle with instanceof logic
  • Create an array of Serviceable
  • Perform service for each Serviceable

Bonus

Add a HybridCar class

What to do?

  • Create a HybridCar class that extends Car.
  • It will need variables for both battery level and fuel level
  • Implement Refuelable and Chargeable together
  • (Optional) Override methods to manage both power sources (driving drains battery first, then gas)

Workflow

  1. Fork the repository to your own Git account
  2. Clone your forked repository
  3. Create a new branch named develop
git checkout -b develop
  1. Complete all TODO sections in the project
  2. Commit your changes with meaningful commit messages
  3. Push your branch to your repository
git push origin develop
  1. Create a Pull Request from develop to main

GOOD LUCK! :)

S
Description
No description provided
Readme
71 KiB
Languages
Java 100%