docs: add README.md
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
# 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
|
||||
```plaintext
|
||||
+-------------------+
|
||||
| Vehicle |
|
||||
| (Abstract Class) |
|
||||
+-------------------+ -----------------+-----------------+--------+
|
||||
^ |
|
||||
| extends |
|
||||
| +-------------------+ |
|
||||
| | Serviceable | <-------+
|
||||
| | (Interface) | implements
|
||||
| +-------------------+
|
||||
+-------------------+
|
||||
| Car |
|
||||
| (Abstract Class) |
|
||||
+-------------------+
|
||||
^
|
||||
| extends
|
||||
+-----------------+-----------------+
|
||||
| |
|
||||
+-------------------+ +-------------------+
|
||||
| GasCar | | ElectricCar |
|
||||
| (Class) | | (Class) |
|
||||
+-------------------+ +-------------------+
|
||||
^
|
||||
| extends
|
||||
+-------------------+
|
||||
| SportsCar |
|
||||
| (Class) |
|
||||
+-------------------+
|
||||
```
|
||||
|
||||
## 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()`
|
||||
|
||||
### 3. GasCar Class
|
||||
- Override `getEnergyType()`
|
||||
- Implement `refuel(double amount)` with validation
|
||||
- Override `showDetails()`
|
||||
|
||||
### 4. ElectricCar Class
|
||||
- Override `getEnergyType()`
|
||||
- Implement `charge(double amount)` with validation
|
||||
- Override `showDetails()`
|
||||
|
||||
### 5. SportsCar Class
|
||||
- Override `showDetails` to include specific Sports Car feature alongside the base class details
|
||||
|
||||
### 6. VehicleInspector Class
|
||||
- Complete the `inspect(Vehicle v)` method using `instanceof`
|
||||
|
||||
### Main Class
|
||||
- Create at least 3 Vehicles
|
||||
#### Example :
|
||||
```java
|
||||
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
|
||||
```
|
||||
4. Complete all TODO sections in the project
|
||||
5. Commit your changes with meaningful commit messages
|
||||
6. Push your branch to your repository
|
||||
```
|
||||
git push origin develop
|
||||
```
|
||||
7. Create a Pull Request from `develop` to `main`
|
||||
|
||||
# GOOD LUCK! :)
|
||||
Reference in New Issue
Block a user