-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAbstractCar.java
More file actions
92 lines (78 loc) · 3.02 KB
/
AbstractCar.java
File metadata and controls
92 lines (78 loc) · 3.02 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package abstractcar;
// Lớp trừu tượng chung cho Car
abstract class Car {
protected String licensePlate;
protected String owner;
protected String vehicleId;
public Car(String licensePlate, String owner, String vehicleId) {
this.licensePlate = licensePlate;
this.owner = owner;
this.vehicleId = vehicleId;
}
// Các phương thức chung
public abstract void showInfo();
}
// Góc nhìn Registration
class RegistrationView extends Car {
private String taxDueDate;
public RegistrationView(String licensePlate, String owner, String vehicleId, String taxDueDate) {
super(licensePlate, owner, vehicleId);
this.taxDueDate = taxDueDate;
}
@Override
public void showInfo() {
System.out.println("=== Registration Info ===");
System.out.println("Vehicle ID: " + vehicleId);
System.out.println("License Plate: " + licensePlate);
System.out.println("Owner: " + owner);
System.out.println("Tax due date: " + taxDueDate);
}
}
// Góc nhìn Owner
class OwnerView extends Car {
private String serviceHistory;
private double mileage;
public OwnerView(String licensePlate, String owner, String vehicleId, String serviceHistory, double mileage) {
super(licensePlate, owner, vehicleId);
this.serviceHistory = serviceHistory;
this.mileage = mileage;
}
@Override
public void showInfo() {
System.out.println("=== Owner Info ===");
System.out.println("Car description: " + vehicleId + " - " + licensePlate);
System.out.println("Service History: " + serviceHistory);
System.out.println("Mileage: " + mileage + " km");
}
}
// Góc nhìn Garage
class GarageView extends Car {
private String workDescription;
private double billingInfo;
public GarageView(String licensePlate, String owner, String vehicleId, String workDescription, double billingInfo) {
super(licensePlate, owner, vehicleId);
this.workDescription = workDescription;
this.billingInfo = billingInfo;
}
@Override
public void showInfo() {
System.out.println("=== Garage Info ===");
System.out.println("License Plate: " + licensePlate);
System.out.println("Work Description: " + workDescription);
System.out.println("Billing Info: $" + billingInfo);
System.out.println("Owner: " + owner);
}
}
// Demo
public class AbstractCar {
public static void main(String[] args) {
Car regCar = new RegistrationView("29A-12345", "Nguyen Van A", "CAR123", "2025-12-31");
Car ownerCar = new OwnerView("29A-12345", "Nguyen Van A", "CAR123", "Oil change, Tire check", 50000);
Car garageCar = new GarageView("29A-12345", "Nguyen Van A", "CAR123", "Brake repair", 250.5);
regCar.showInfo();
System.out.println();
ownerCar.showInfo();
System.out.println();
garageCar.showInfo();
}
}