Implement main file as instructions

This commit is contained in:
2026-04-27 21:45:22 +03:30
parent 54f2e13683
commit c65c28290b
+49 -10
View File
@@ -1,8 +1,30 @@
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;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
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
);
// ============================================================
// TODO 1:
// Create one instance of each vehicle type:
@@ -18,9 +40,10 @@ public class Main {
// ============================================================
ArrayList<Vehicle> vehicles = new ArrayList<>();
vehicles.add(tesla);
vehicles.add(toyota);
vehicles.add(ferrari);
// ============================================================
// TODO 2:
// Create an array of Vehicle:
@@ -35,7 +58,10 @@ public class Main {
for (Vehicle v: vehicles) {
v.basicInfo();
System.out.print("\n");
}
// ============================================================
// TODO 3:
// Loop through the Vehicle[] array and:
@@ -50,7 +76,9 @@ public class Main {
for (Vehicle v: vehicles) {
VehicleInspector.inspect(v);
}
// ============================================================
// TODO 4:
// Use VehicleInspector to inspect each vehicle:
@@ -65,7 +93,10 @@ public class Main {
ArrayList<Serviceable> serviceables= new ArrayList<>();
serviceables.add(tesla);
serviceables.add(toyota);
serviceables.add(ferrari);
// ============================================================
// TODO 5:
// Create an array of Serviceable:
@@ -83,7 +114,17 @@ public class Main {
for (Serviceable s: serviceables) {
Vehicle v = (Vehicle) s;
if(s.needsService(v)) {
System.out.println("Brand: " + v.getBrand() +", model: " +
v.getModel());
s.performService();
} else {
System.out.println("The car does not need service");
}
System.out.print("\n");
}
// ============================================================
// TODO 6:
// Loop through the Serviceable[] array:
@@ -107,9 +148,7 @@ public class Main {
// ============================================================
System.out.println("=== Workshop Completed ===");
// ============================================================
// TODO 7 (Optional):
// After everything is done, print a final message: