-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMech.java
More file actions
42 lines (36 loc) · 969 Bytes
/
Mech.java
File metadata and controls
42 lines (36 loc) · 969 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
import java.util.ArrayList;
/***
* The class of a garage that stores cars based on the specific car type
* @param <T>
*/
public class Mech <T extends Car> {
private final int maxLoad;
private int load;
private ArrayList<T> mechGarage;
/***
* Gives the garage a car limit and a list of the cars that are stored
* @param maxLoad
*/
public Mech(int maxLoad) {
this.maxLoad = maxLoad;
mechGarage = new ArrayList<T>();
}
/***
* Stores a car in the garage
* @param car of the specific type cartype
*/
public void load(T car) {
if(load + 1 > maxLoad) return;
mechGarage.add(car);
load++;
}
/***
* Removes a car from the garage
* @return returns the car that was removed
*/
public T unoload() {
T car = mechGarage.remove(mechGarage.size() - 1);
load--;
return car;
}
}