-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRental.java
More file actions
47 lines (38 loc) · 936 Bytes
/
Rental.java
File metadata and controls
47 lines (38 loc) · 936 Bytes
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
import java.util.ArrayList;
public class Rental {
private final String name;
private final ArrayList<Vehicle> vehicles;
public Rental(String name) {
this.name = name;
vehicles = new ArrayList<>();
}
public String getName() {
return name;
}
public ArrayList<Vehicle> getVehicles() {
return vehicles;
}
public void addVehicle(Vehicle vehicle) {
vehicles.add(vehicle);
}
public void addAllVehicles(Vehicle... vehicles) {
for (Vehicle v : vehicles) {
this.vehicles.add(v);
}
}
public void transformAllTrucks() {
for (Vehicle c : vehicles) {
if (c instanceof Truck) {
Truck t = (Truck) c;
if (!t.isTransformed()) t.transform();
}
}
}
public String toString() {
String result = name + "\n" + "Unsere Fahrzeuge: \n";
for (Vehicle vehicle : vehicles) {
result += vehicle.toString() + "\n";
}
return result;
}
}