-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotorcycle.java
More file actions
45 lines (40 loc) · 1.51 KB
/
Copy pathMotorcycle.java
File metadata and controls
45 lines (40 loc) · 1.51 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
/**
* Motorcycle class implements both Vehicle and MotorVehicle interfaces.
* Represents a motorcycle in the rental system.
*/
public class Motorcycle implements Vehicle, MotorVehicle {
private String make;
private String model;
private int year;
private int numberOfWheels;
private String typeOfMotorcycle;
public Motorcycle(String make, String model, int year) {
this.make = make;
this.model = model;
this.year = year;
}
public String getMake() { return make; }
public String getModel() { return model; }
public int getYearOfManufacture() { return year; }
public void setNumberOfWheels(int wheels) {
if (wheels != 2 && wheels != 3) {
throw new IllegalArgumentException("Motorcycles have 2 or 3 wheels");
}
this.numberOfWheels = wheels;
}
public int getNumberOfWheels() { return numberOfWheels; }
public void setTypeOfMotorcycle(String type) {
if (!type.equalsIgnoreCase("sport") &&
!type.equalsIgnoreCase("cruiser") &&
!type.equalsIgnoreCase("off-road")) {
throw new IllegalArgumentException("Type must be sport, cruiser, or off-road");
}
this.typeOfMotorcycle = type;
}
public String getTypeOfMotorcycle() { return typeOfMotorcycle; }
@Override
public String toString() {
return "Motorcycle: " + make + " " + model + " (" + year + "), " +
numberOfWheels + " wheels, " + typeOfMotorcycle;
}
}