New: sorted kontoliste with treeset

main
Caner Aliji 2022-12-01 13:50:45 +01:00
parent 9ad8c5760b
commit 9d7e6a7357
2 changed files with 15 additions and 2 deletions

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 static final long serialVersionUID = 1L;
@ -83,5 +83,14 @@ public class Konto implements Serializable {
return stand;
}
@Override
public int compareTo(Object o) {
Konto k = (Konto) o;
return (int) (k.getKontostand() - this.getKontostand());
}
}

View File

@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.bank.facade;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeSet;
import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Depot;
@ -61,10 +62,13 @@ public class Banksystem {
public String[] getKontenlisteForKunde(){
Collection<Konto> konten = bank.getKundenKonto(currentKunde);
TreeSet<Konto> ts = new TreeSet<Konto>(konten);
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
for (Konto k : ts) {
liste[i++] = k.toString();
}