completing TODO parts.

This commit is contained in:
2026-04-29 00:22:52 +03:30
parent 6cb8f9a8d8
commit 81b635df0c
7 changed files with 174 additions and 25 deletions
+31 -12
View File
@@ -1,5 +1,12 @@
package org;
import org.behavior.Serviceable;
import org.model.ElectricCar;
import org.model.GasCar;
import org.model.SportsCar;
import org.model.Vehicle;
import org.util.VehicleInspector;
public class Main {
public static void main(String[] args) {
@@ -17,9 +24,9 @@ public class Main {
// ElectricCar tesla = new ElectricCar(...);
// ============================================================
ElectricCar nissan = new ElectricCar("Nissan", "Leaf", 2022, 850, 5, 62, 88.5);
GasCar ford = new GasCar("Ford", "Mustang", 2023, 12000, 4, 55.0, "Petrol");
SportsCar porsche = new SportsCar("Porsche", "911 Turbo S", 2023, 5000, 2, 55.0, "Petrol", 2.6);
// ============================================================
// TODO 2:
@@ -32,6 +39,7 @@ public class Main {
// as their parent type (Vehicle).
// ============================================================
Vehicle[] vehicles = {nissan, ford, porsche};
@@ -47,7 +55,10 @@ public class Main {
// behavior and can call inherited methods.
// ============================================================
for(Vehicle v: vehicles){
v.basicInfo();
System.out.println();
}
@@ -62,6 +73,9 @@ public class Main {
// • Show subclassspecific inspection messages
// ============================================================
for (Vehicle v : vehicles) {
VehicleInspector.inspect(v);
}
@@ -80,9 +94,7 @@ public class Main {
//
// ============================================================
Serviceable[] serviceables = {nissan, ford, porsche};
// ============================================================
// TODO 6:
@@ -106,6 +118,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() + " needs service.");
s.performService();
System.out.println();
} else {
System.out.println(v.getBrand() + " " + v.getModel() + " does not need service.");
}
System.out.println();
}
@@ -117,10 +140,6 @@ public class Main {
// System.out.println("=== Workshop Completed ===");
//
// ============================================================
System.out.println("=== Workshop Completed ===");
}
}