DexterHK 2022-12-11 19:51:09 +01:00
parent 575ec55f9e
commit 94a9feba9f
2 changed files with 26 additions and 8 deletions

View File

@ -24,13 +24,7 @@ public class Bank implements Serializable {
} }
public int addKonto(String name, Kontoart kontoart) { public int addKonto(String name, Kontoart kontoart) {
Konto k; Konto k;
// switch (kontoart) {
// case Sparkonto: System.out.println("sk"); break;
// case Girokonto: System.out.println("gk");
// }
if (kontoart == Kontoart.Sparkonto) if (kontoart == Kontoart.Sparkonto)
k = new Konto(name, ++kontozähler); k = new Konto(name, ++kontozähler);
else else
@ -105,6 +99,24 @@ Collection<Konto> minus = kontenTemp.stream().filter(n -> n.getKontostand()<0)
return minus; return minus;
} }
//Selection
public void sort(Comparable[] a)
{
int N = a.length; // array length
for (int i = 0; i < N; i++)
{ // Exchange a[i] with smallest entry in a[i+1...N).
int min = i; // index of minimal entr.
for (int j = i+1; j < N; j++)
if (less(a[j], a[min])) min = j;
exch(a, i, min);
}
}
private static boolean less(Comparable v, Comparable w)
{ return v.compareTo(w) < 0; }
private static void exch(Comparable[] a, int i, int j)
{ Comparable t = a[i]; a[i] = a[j]; a[j] = t; }

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;
@ -77,4 +77,10 @@ public class Konto implements Serializable {
return k; return k;
} }
@Override
public int compareTo(Object o) {
return this.compareTo(o);
}
} }