-
Notifications
You must be signed in to change notification settings - Fork 0
/
CombustionCar.java
60 lines (45 loc) · 1.45 KB
/
CombustionCar.java
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
package P8;
public class CombustionCar extends Car {
// Atributos de instancia
private int mechanicalPower;
// Atributos estáticos
private static int minPower = 60;
private static int maxPower = 500;
// Constructor vacío
public CombustionCar() {
}
// Constructor con argumentos
public CombustionCar(String plate, String manufacturer, int mechanicalPower) {
super(plate, manufacturer);
this.mechanicalPower = mechanicalPower;
}
// Métodos estáticos o de clase
public static boolean isValidPower(int mechanicalPower) {
if (mechanicalPower >= minPower && mechanicalPower <= maxPower) {
return true;
} else {
System.out.println(
"Incorrect power value: " + mechanicalPower + ". Valid range is " + minPower + "-" + maxPower);
return false;
}
}
// Métodos de instancia
public int getMechanicalPower() {
return this.mechanicalPower;
}
public void setMechanicalPower(int mechanicalPower) {
this.mechanicalPower = mechanicalPower;
}
public void setMinPower(int minPower) {
CombustionCar.minPower = minPower;
}
public void setMaxPower(int maxPower) {
CombustionCar.maxPower = maxPower;
}
public int getTotalPower() {
return this.mechanicalPower;
}
public String toString() {
return "C" + super.toString() + mechanicalPower;
}
}