Implement main file as instructions
This commit is contained in:
+49
-10
@@ -1,8 +1,30 @@
|
|||||||
package org;
|
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 class Main {
|
||||||
public static void main(String[] args) {
|
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:
|
// TODO 1:
|
||||||
// Create one instance of each vehicle type:
|
// 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:
|
// TODO 2:
|
||||||
// Create an array of Vehicle:
|
// Create an array of Vehicle:
|
||||||
@@ -35,7 +58,10 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (Vehicle v: vehicles) {
|
||||||
|
v.basicInfo();
|
||||||
|
System.out.print("\n");
|
||||||
|
}
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// TODO 3:
|
// TODO 3:
|
||||||
// Loop through the Vehicle[] array and:
|
// Loop through the Vehicle[] array and:
|
||||||
@@ -50,7 +76,9 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
for (Vehicle v: vehicles) {
|
||||||
|
VehicleInspector.inspect(v);
|
||||||
|
}
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// TODO 4:
|
// TODO 4:
|
||||||
// Use VehicleInspector to inspect each vehicle:
|
// 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:
|
// TODO 5:
|
||||||
// Create an array of Serviceable:
|
// 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:
|
// TODO 6:
|
||||||
// Loop through the Serviceable[] array:
|
// Loop through the Serviceable[] array:
|
||||||
@@ -107,9 +148,7 @@ public class Main {
|
|||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Workshop Completed ===");
|
||||||
|
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// TODO 7 (Optional):
|
// TODO 7 (Optional):
|
||||||
// After everything is done, print a final message:
|
// After everything is done, print a final message:
|
||||||
|
|||||||
Reference in New Issue
Block a user