-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
68 lines (55 loc) · 2.91 KB
/
Copy pathMain.java
File metadata and controls
68 lines (55 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* Main class demonstrating the Vehicle Management System
* Shows all OOP principles: Abstraction, Inheritance, Encapsulation, and Polymorphism
*/
public class Main {
public static void main(String[] args) {
System.out.println("===============================================");
System.out.println(" VEHICLE MANAGEMENT SYSTEM DEMONSTRATION");
System.out.println("===============================================\n");
// Create a Garage instance
Garage garage = new Garage();
// Create various vehicle instances - Demonstrating Polymorphism
System.out.println(">>> CREATING VEHICLES <<<\n");
Car car1 = new Car("John Smith", "Toyota", "Camry", 2022, 5);
Car car2 = new Car("Emma Johnson", "Honda", "Civic", 2021, 5);
Truck truck1 = new Truck("Michael Brown", "Volvo", "FH16", 2020, 25.5);
Truck truck2 = new Truck("David Lee", "Scania", "R440", 2019, 20.0);
Motorcycle bike1 = new Motorcycle("Sarah Wilson", "Harley-Davidson", "Street 750", 2023, 750);
Motorcycle bike2 = new Motorcycle("James Taylor", "Yamaha", "YZF-R1", 2022, 998);
// Add vehicles to the garage
System.out.println(">>> ADDING VEHICLES TO GARAGE <<<\n");
garage.addVehicle(car1);
garage.addVehicle(car2);
garage.addVehicle(truck1);
garage.addVehicle(truck2);
garage.addVehicle(bike1);
garage.addVehicle(bike2);
// Display all vehicles - Polymorphism in action
garage.displayVehicles();
// Display specific vehicle details
System.out.println(">>> DISPLAYING SPECIFIC VEHICLE DETAILS <<<");
garage.displayVehicleDetails("John Smith");
garage.displayVehicleDetails("Michael Brown");
garage.displayVehicleDetails("Sarah Wilson");
// Update a vehicle
System.out.println(">>> UPDATING VEHICLE DETAILS <<<\n");
garage.updateVehicle("Emma Johnson", "Emily Johnson", "Honda", "Accord", 2023);
garage.displayVehicleDetails("Emily Johnson");
// Remove a vehicle
System.out.println(">>> REMOVING A VEHICLE <<<\n");
garage.removeVehicle("David Lee");
System.out.println("Updated garage count: " + garage.getCount() + " vehicles\n");
// Display updated vehicle list
System.out.println(">>> FINAL GARAGE STATE <<<");
garage.displayVehicles();
// Demonstrate attempted operations on non-existent vehicles
System.out.println(">>> TESTING ERROR HANDLING <<<\n");
garage.displayVehicleDetails("NonExistent Owner");
garage.removeVehicle("NonExistent Owner");
garage.updateVehicle("NonExistent Owner", "New Owner", "Brand", "Model", 2024);
System.out.println("===============================================");
System.out.println(" END OF DEMONSTRATION");
System.out.println("===============================================");
}
}