-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.java
More file actions
106 lines (79 loc) · 2.54 KB
/
Car.java
File metadata and controls
106 lines (79 loc) · 2.54 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
public class Car{
private String description;
public Car(String description) {
this.description = description;
}
public void startEngine(){
System.out.println("Car -> startEngine");
}
public void drive(){
System.out.println("Car -> Driving, type is " + getClass().getSimpleName());
runEngine();
}
protected void runEngine(){
System.out.println("Car -> runEngine");
}
}
class GasPoweredCar extends Car{
private double avgKmPerLitre;
private int cylinders = 6;
public GasPoweredCar(String description) {
super(description);
}
public GasPoweredCar(String description, double avgKmPerLitre, int cylinders) {
super(description);
this.avgKmPerLitre = avgKmPerLitre;
this.cylinders = cylinders;
}
@Override
public void startEngine() {
System.out.printf("Gas -> ALl %d cylinders are fired up, Ready!%n",cylinders);
}
@Override
protected void runEngine() {
System.out.printf("Gas -> usage exceeds the average: %.2f %n",avgKmPerLitre);
}
}
class ElectricCar extends Car{
private double avgKmPerCharge;
private int batterySize = 6;
public ElectricCar(String description) {
super(description);
}
public ElectricCar(String description, double avgKmPerCharge, int cylinders) {
super(description);
this.avgKmPerCharge = avgKmPerCharge;
this.batterySize = cylinders;
}
@Override
public void startEngine() {
System.out.printf("BEV -> switch %d kWh battery on, Ready!%n", batterySize);
}
@Override
protected void runEngine() {
System.out.printf("BEV -> usage under the average: %.2f %n", avgKmPerCharge);
}
}
class HybridCar extends Car{
private double avgKmPerLitre;
private int cylinders = 6;
private int batterySize;
public HybridCar(String description) {
super(description);
}
public HybridCar(String description, double avgKmPerLitre, int cylinders,int batterySize) {
super(description);
this.avgKmPerLitre = avgKmPerLitre;
this.cylinders = cylinders;
this.batterySize = batterySize;
}
@Override
public void startEngine() {
System.out.printf("Hybrid -> ALl %d cylinders are fired up, Ready!%n",cylinders);
System.out.printf("Hybrid -> switch %d kWh battery on, Ready!%n", batterySize);
}
@Override
protected void runEngine() {
System.out.printf("Hybrid -> usage below average: %.2f %n",avgKmPerLitre);
}
}