Methoden verbessert
parent
e6f149e7f9
commit
e16fb0b1ab
|
@ -35,6 +35,14 @@ public class Packstation {
|
|||
* @throws IllegalStateException Wenn kein Platz mehr in der Packstation ist.
|
||||
*/
|
||||
public Point legePaketAb(Paket paket) throws IllegalStateException {
|
||||
for (int i=0; i < station.length; i++) {
|
||||
for(int j=0; j < station[i].length; j++) {
|
||||
if (station[i][j] == null) {
|
||||
station[i][j] = paket;
|
||||
return new Point(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Kein Platz mehr in der Packstation.");
|
||||
}
|
||||
|
||||
|
@ -69,13 +77,34 @@ public class Packstation {
|
|||
* @throws IllegalArgumentException Wenn die angegebene Box nicht existiert.
|
||||
*/
|
||||
public String informationZumBoxenplatz(int spalte, int reihe) throws IllegalArgumentException {
|
||||
|
||||
String empfaenger = station[spalte][reihe].getEmpfaenger();
|
||||
String anschrift = station[spalte][reihe].getAnschrift();
|
||||
if (empfaenger == null && anschrift == null) {
|
||||
if (spalte >= station.length || reihe >= station[spalte].length)
|
||||
throw new IllegalArgumentException("Die angegebene Box existiert nicht.");
|
||||
else if (station[spalte][reihe] == null)
|
||||
return "Die Box ist leer.";
|
||||
else
|
||||
return station[spalte][reihe].toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Packstation formatiert aus bei Werten von 0-9
|
||||
*/
|
||||
public void printStation() {
|
||||
System.out.print(" ");
|
||||
for (int i=0; i < station[0].length; i++)
|
||||
System.out.print("---------- ");
|
||||
System.out.print("\n");
|
||||
|
||||
for (int j = station.length-1; j >= 0; j--) {
|
||||
System.out.print("|");
|
||||
for (int i = 0; i < station[j].length; i++) {
|
||||
System.out.printf(" [%d][%d] |", j, i);
|
||||
}
|
||||
System.out.print("\n");
|
||||
System.out.print(" ");
|
||||
for (int i=0; i < station[0].length; i++)
|
||||
System.out.print("---------- ");
|
||||
System.out.print("\n");
|
||||
}
|
||||
|
||||
return empfaenger + "\n" + anschrift;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue