Compare commits

..

1 Commits

Author SHA1 Message Date
Oliver Hummel 3c8c557262 Experimentelle Sortierung der Kontenliste 2022-11-29 14:07:07 +01:00
3 changed files with 20 additions and 3 deletions

View File

@ -2,6 +2,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.Collections;
import java.util.HashMap; import java.util.HashMap;
public class Bank implements Serializable { public class Bank implements Serializable {

View File

@ -3,7 +3,7 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
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;
@ -23,7 +23,7 @@ public class Konto implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]"; return "Konto "+ stand + "[nummer=" + nummer + ", inhaber=" + inhaber + "]";
} }
public String getInhaber() { public String getInhaber() {
@ -73,4 +73,12 @@ 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);
return this.inhaber.compareTo(kOther.inhaber);
}
} }

View File

@ -1,6 +1,9 @@
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 java.util.TreeSet;
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;
@ -27,10 +30,15 @@ public class Banksystem {
public String[] getKontenliste() { public String[] getKontenliste() {
Collection<Konto> konten = bank.getKontenliste(); Collection<Konto> konten = bank.getKontenliste();
TreeSet<Konto> ts = new TreeSet<>(konten);
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 : ts) {
liste[i++] = k.toString(); liste[i++] = k.toString();
} }