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:
|
public class Flasche<G extends Getränk, V extends Verschluss> {
private G getränk;
private V verschluss;
public Flasche(G geschmack, V verschluss) {
this.getränk = geschmack;
this.verschluss = verschluss;
}
public V oeffen() throws NullPointerException {
if (this.verschluss == null) {
throw new NullPointerException("Flasche schon geöffnet");
} else {
V x = this.verschluss;
this.verschluss = null;
return x;
}
}
public G leeren() throws NullPointerException {
if (this.verschluss == null && this.getränk != null) {
G x = this.getränk;
this.getränk = null;
return x;
} else {
throw new NullPointerException(
"Flasche noch zu oder bereits geöffnet");
}
}
} |