-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCrate.java
More file actions
39 lines (34 loc) · 929 Bytes
/
Crate.java
File metadata and controls
39 lines (34 loc) · 929 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
public class Crate {
private Bottle box1;
private Bottle box2;
private Bottle box3;
private Bottle box4;
private Bottle box5;
private Bottle box6;
public void insertBottle(Bottle bottle, int box) throws CrateIndexOutOfBoundsException {
if (box < 1 || box > 6) {
throw new CrateIndexOutOfBoundsException();
}
switch (box) {
case 1 -> box1 = bottle;
case 2 -> box2 = bottle;
case 3 -> box3 = bottle;
case 4 -> box4 = bottle;
case 5 -> box5 = bottle;
case 6 -> box6 = bottle;
}
}
public Bottle takeBottle(int box) throws CrateIndexOutOfBoundsException {
if (box < 1 || box > 6) {
throw new CrateIndexOutOfBoundsException();
}
return switch (box) {
case 1 -> box1;
case 2 -> box2;
case 3 -> box3;
case 4 -> box4;
case 5 -> box5;
default -> box6;
};
}
}