Konten nach Stand sortierbar

main
student 2022-11-29 13:57:10 +01:00
parent 30ed711172
commit f629d1e365
3 changed files with 23 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.TreeMap;
public class Bank implements Serializable { public class Bank implements Serializable {
private String name; private String name;

View File

@ -2,8 +2,9 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.lang.Comparable;
public class Konto implements Serializable { public class Konto implements Serializable, Comparable {
private int nummer; private int nummer;
protected long stand = 0; protected long stand = 0;
private String inhaber; private String inhaber;
@ -15,7 +16,7 @@ public class Konto implements Serializable {
this.inhaber = inhaber; this.inhaber = inhaber;
this.kontobewegungen = new ArrayList<>(); this.kontobewegungen = new ArrayList<>();
}// }
public int getKontonummer() { public int getKontonummer() {
return nummer; return nummer;
@ -23,7 +24,7 @@ public class Konto implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]"; return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + ", stand=" + stand + "]";
} }
public String getInhaber() { public String getInhaber() {
@ -73,4 +74,10 @@ public class Konto implements Serializable {
return saldo; return saldo;
} }
@Override
public int compareTo(Object other) {
Konto kOther = (Konto) other;
return (int) (this.stand - kOther.stand); //etwas negatives, positives oder 0
}
} }

View File

@ -1,6 +1,8 @@
package de.hs_mannheim.informatik.bank.facade; package de.hs_mannheim.informatik.bank.facade;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import de.hs_mannheim.informatik.bank.domain.Bank; import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Girokonto; import de.hs_mannheim.informatik.bank.domain.Girokonto;
@ -21,10 +23,6 @@ public class Banksystem {
public int kontoAnlegen(String name, int auswahl, int kundennummer) throws Exception { public int kontoAnlegen(String name, int auswahl, int kundennummer) throws Exception {
int kontonummer = bank.addKonto(name, auswahl, kundennummer); int kontonummer = bank.addKonto(name, auswahl, kundennummer);
//Wenn neuerKunde true, fuege Konto zum neuen Kunden hinzu
Persistenz.speichereBankDaten(this.bank, bank.getName()); Persistenz.speichereBankDaten(this.bank, bank.getName());
return kontonummer; return kontonummer;
@ -32,10 +30,18 @@ public class Banksystem {
public String[] getKontenliste() { public String[] getKontenliste() {
Collection<Konto> konten = bank.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()]; String[] liste = new String[konten.size()];
int i = 0; int i = 0;
for (Konto k : konten) { for (Konto k : al) {
liste[i++] = k.toString(); liste[i++] = k.toString();
} }