implement Vehicle Management System

This commit is contained in:
2026-04-28 21:58:42 +03:30
parent e8aedb8354
commit 6ae0cdb95d
7 changed files with 211 additions and 14 deletions
+38 -14
View File
@@ -1,5 +1,12 @@
package org;
import org.model.ElectricCar;
import org.model.GasCar;
import org.model.SportsCar;
import org.model.Vehicle;
import org.util.VehicleInspector;
import org.behavior.Serviceable;
public class Main {
public static void main(String[] args) {
@@ -17,8 +24,15 @@ public class Main {
// ElectricCar tesla = new ElectricCar(...);
// ============================================================
ElectricCar chevrolet = new ElectricCar("Chevrolet", "Bolt EV",
2023, 8500, 5, 65, 80) ;
GasCar toyota = new GasCar("Toyota", "Camery",
2022, 45000, 5, 65, "Petrol");
SportsCar lamborghini = new SportsCar("Lamborghini", "Huracan EVO",
2022, 9500, 2, 55, "Petrol",
3.2) ;
// ============================================================
@@ -32,8 +46,7 @@ public class Main {
// as their parent type (Vehicle).
// ============================================================
Vehicle[] vehicle = {chevrolet, toyota, lamborghini};
// ============================================================
@@ -47,9 +60,11 @@ public class Main {
// behavior and can call inherited methods.
// ============================================================
for (Vehicle v : vehicle)
{
v.basicInfo();
System.out.println();
}
// ============================================================
// TODO 4:
@@ -62,9 +77,11 @@ public class Main {
// • Show subclassspecific inspection messages
// ============================================================
for(Vehicle v : vehicle)
{
VehicleInspector.inspect(v) ;
System.out.println();
}
// ============================================================
// TODO 5:
@@ -80,9 +97,7 @@ public class Main {
//
// ============================================================
Serviceable[] serviceables = {chevrolet, toyota, lamborghini};
// ============================================================
// TODO 6:
@@ -106,6 +121,17 @@ public class Main {
// Add blank lines between each item for readability.
// ============================================================
for (Serviceable s : serviceables)
{
Vehicle v = (Vehicle) s;
if (s.needsService(v))
{
System.out.println(v.getBrand() + " " + v.getModel() + " need service !!");
s.performService();
}
else
System.out.println(v.getBrand() + "" + v.getModel() + "" + " does not need service :)");
}
@@ -118,9 +144,7 @@ public class Main {
//
// ============================================================
System.out.println("=== Workshop Completed ===");
}
}