-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSport.java
More file actions
63 lines (51 loc) · 1.77 KB
/
Copy pathSport.java
File metadata and controls
63 lines (51 loc) · 1.77 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
package carbookingsystem1;
public class Sport extends Car {
private double speed;
private int enginePower;
public Sport(int carID, String carModel, SpecialFeature[] f, boolean availability, String color, double speed, int enginePower) {
super(carID, carModel, f, availability, color); // Call the constructor of the Car class
setSpeed(speed); // Set the speed using the setter method
setEnginePower(enginePower); // Set the engine type using the setter method
}
// Empty constructor
public Sport() {
this(0, "", null, false, "", 0.0, 0); // Call the empty constructor of the Car class
}
// Getter for speed
public double getSpeed() {
return speed;
}
// Setter for speed
public void setSpeed(double speed) {
this.speed = speed;
}
// Getter for engine type
public int getEnginePower() {
return enginePower;
}
// Setter for engine type
public void setEnginePower(int engineType) {
this.enginePower = engineType;
}
// Method for sport mode
public void sportMode() {
if (getEnginePower() >= 500) {
System.out.println("sport mode Activated");
} else {
System.out.println("This Car does not support sport mode");
}
}
// Implementing the abstract method from the Car class
@Override
public int calculateRentalPrice() {
if (getSpeed() >= 400) {
return 500;
}
return 350;
}
// toString method to represent the object as a string
@Override
public String toString() {
return String.format("%s Speed: %.1f%n EnginePower: %d%n", super.toString(), speed, enginePower);
}
}