Complete Car project implementation.

This commit is contained in:
Fatemesadat Mirabootalebi
2026-05-02 12:03:14 -07:00
parent 6cb8f9a8d8
commit 6903f5c0ad
7 changed files with 156 additions and 17 deletions
+30 -8
View File
@@ -1,4 +1,7 @@
package org;
import org.model.*;
import org.behavior.*;
import org.util.*;
public class Main {
public static void main(String[] args) {
@@ -16,7 +19,9 @@ public class Main {
// • Store them in variables such as:
// ElectricCar tesla = new ElectricCar(...);
// ============================================================
ElectricCar tesla = new ElectricCar("Tesla", "Model S", 2023, 9000, 5, 100, 85);
GasCar toyota = new GasCar("Toyota", "Camry", 2020, 15000, 5, 60, "Gasoline");
SportsCar ferrari = new SportsCar("Ferrari", "SF90", 2024, 4000, 2, 70, "Premium", 2.5);
@@ -31,6 +36,7 @@ public class Main {
// subclasses (ElectricCar, GasCar, SportsCar) are stored
// as their parent type (Vehicle).
// ============================================================
Vehicle[] vehicles = {tesla, toyota, ferrari};
@@ -46,7 +52,10 @@ public class Main {
// Demonstrate that all subclasses share the same Vehicle
// behavior and can call inherited methods.
// ============================================================
for (Vehicle v : vehicles){
v.basicInfo();
System.out.println();
}
@@ -61,7 +70,10 @@ public class Main {
// • Demonstrate the use of `instanceof`
// • Show subclassspecific inspection messages
// ============================================================
for (Vehicle v : vehicles){
VehicleInspector.inspect(v);
System.out.println();
}
@@ -79,7 +91,7 @@ public class Main {
// Vehicle v = (Vehicle) s;
//
// ============================================================
Serviceable[] serviceables = {tesla, toyota, ferrari};
@@ -105,6 +117,19 @@ 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();
}
else{
System.out.println(v.getBrand() + " " + v.getModel() + " does not need service.");
}
System.out.println();
}
@@ -117,10 +142,7 @@ public class Main {
// System.out.println("=== Workshop Completed ===");
//
// ============================================================
System.out.println("=== Workshop Completed ===");
}
}