Konten nach Stand sortierbar
parent
30ed711172
commit
f629d1e365
|
@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.bank.domain;
|
|||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Bank implements Serializable {
|
||||
private String name;
|
||||
|
|
|
@ -2,8 +2,9 @@ package de.hs_mannheim.informatik.bank.domain;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.Comparable;
|
||||
|
||||
public class Konto implements Serializable {
|
||||
public class Konto implements Serializable, Comparable {
|
||||
private int nummer;
|
||||
protected long stand = 0;
|
||||
private String inhaber;
|
||||
|
@ -15,7 +16,7 @@ public class Konto implements Serializable {
|
|||
this.inhaber = inhaber;
|
||||
|
||||
this.kontobewegungen = new ArrayList<>();
|
||||
}//
|
||||
}
|
||||
|
||||
public int getKontonummer() {
|
||||
return nummer;
|
||||
|
@ -23,7 +24,7 @@ public class Konto implements Serializable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]";
|
||||
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + ", stand=" + stand + "]";
|
||||
}
|
||||
|
||||
public String getInhaber() {
|
||||
|
@ -73,4 +74,10 @@ public class Konto implements Serializable {
|
|||
return saldo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object other) {
|
||||
Konto kOther = (Konto) other;
|
||||
return (int) (this.stand - kOther.stand); //etwas negatives, positives oder 0
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Girokonto;
|
||||
|
@ -19,11 +21,7 @@ public class Banksystem {
|
|||
}
|
||||
|
||||
public int kontoAnlegen(String name, int auswahl, int kundennummer) throws Exception {
|
||||
int kontonummer = bank.addKonto(name, auswahl, kundennummer);
|
||||
|
||||
|
||||
//Wenn neuerKunde true, fuege Konto zum neuen Kunden hinzu
|
||||
|
||||
int kontonummer = bank.addKonto(name, auswahl, kundennummer);
|
||||
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
|
@ -32,10 +30,18 @@ public class Banksystem {
|
|||
|
||||
public String[] getKontenliste() {
|
||||
Collection<Konto> konten = bank.getKontenliste();
|
||||
ArrayList<Konto> al = new ArrayList<>();
|
||||
|
||||
for(Konto k : konten) {
|
||||
al.add(k);
|
||||
}
|
||||
|
||||
Collections.sort(al);
|
||||
|
||||
String[] liste = new String[konten.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Konto k : konten) {
|
||||
for (Konto k : al) {
|
||||
liste[i++] = k.toString();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue