diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Bank.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Bank.java index 3407c4c..9931788 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Bank.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Bank.java @@ -24,13 +24,7 @@ public class Bank implements Serializable { } public int addKonto(String name, Kontoart kontoart) { - Konto k; - -// switch (kontoart) { -// case Sparkonto: System.out.println("sk"); break; -// case Girokonto: System.out.println("gk"); -// } - + Konto k; if (kontoart == Kontoart.Sparkonto) k = new Konto(name, ++kontozähler); else @@ -105,6 +99,24 @@ Collection minus = kontenTemp.stream().filter(n -> n.getKontostand()<0) 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; } + + diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Konto.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Konto.java index 322227e..415ca82 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Konto.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Konto.java @@ -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; @@ -77,4 +77,10 @@ public class Konto implements Serializable { return k; } + @Override + public int compareTo(Object o) { + + return this.compareTo(o); + } + }