Experimentelle Sortierung der Kontenliste

treesetExample
Oliver Hummel 2022-11-29 14:07:07 +01:00
parent 44541d7255
commit 3c8c557262
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.util.Collection;
import java.util.Collections;
import java.util.HashMap;
public class Bank implements Serializable {

View File

@ -3,7 +3,7 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable;
import java.util.ArrayList;
public class Konto implements Serializable {
public class Konto implements Serializable, Comparable {
private int nummer;
protected long stand = 0;
private String inhaber;
@ -23,7 +23,7 @@ public class Konto implements Serializable {
@Override
public String toString() {
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]";
return "Konto "+ stand + "[nummer=" + nummer + ", inhaber=" + inhaber + "]";
}
public String getInhaber() {
@ -73,4 +73,12 @@ public class Konto implements Serializable {
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;
import java.util.ArrayList;
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.Girokonto;
@ -27,10 +30,15 @@ public class Banksystem {
public String[] getKontenliste() {
Collection<Konto> konten = bank.getKontenliste();
TreeSet<Konto> ts = new TreeSet<>(konten);
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
for (Konto k : ts) {
liste[i++] = k.toString();
}