Skip to content

Commit 951e519

Browse files
committed
implement solution
1 parent 5bd4b26 commit 951e519

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Crate.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
public class Crate {
1+
public class Crate<T> {
22

3-
private Bottle box1;
4-
private Bottle box2;
5-
private Bottle box3;
6-
private Bottle box4;
7-
private Bottle box5;
8-
private Bottle box6;
93

10-
public void insertBottle(Bottle bottle, int box) throws CrateIndexOutOfBoundsException {
4+
private T box1;
5+
private T box2;
6+
private T box3;
7+
private T box4;
8+
private T box5;
9+
private T box6;
10+
11+
public void insertBottle(T bottle, int box) throws CrateIndexOutOfBoundsException {
1112
if (box < 1 || box > 6) {
1213
throw new CrateIndexOutOfBoundsException();
1314
}
@@ -22,7 +23,7 @@ public void insertBottle(Bottle bottle, int box) throws CrateIndexOutOfBoundsExc
2223
}
2324
}
2425

25-
public Bottle takeBottle(int box) throws CrateIndexOutOfBoundsException {
26+
public T takeBottle(int box) throws CrateIndexOutOfBoundsException {
2627
if (box < 1 || box > 6) {
2728
throw new CrateIndexOutOfBoundsException();
2829
}

Exercise.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
public class Exercise {
22

33
public static void main(String[] args) {
4-
Crate crate = new Crate();
4+
Crate<Bottle> crate = new Crate<Bottle>();
55

66
try {
77
crate.insertBottle(new BeerBottle(), 1);

0 commit comments

Comments
 (0)