DexterHK 2022-12-11 19:29:09 +01:00
parent 51e5225a68
commit 575ec55f9e
3 changed files with 56 additions and 32 deletions

View File

@ -1,6 +1,7 @@
package de.hs_mannheim.informatik.bank.domain; package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -62,15 +63,8 @@ public class Bank implements Serializable {
case 2: return temp.get(Kontoart.Girokonto); case 2: return temp.get(Kontoart.Girokonto);
case 3: return temp.get(Kontoart.Tagesgeldkonto); case 3: return temp.get(Kontoart.Tagesgeldkonto);
default: default:
List<Konto> output = null; List<Konto> output = temp.values().stream().flatMap(y -> y.stream())
for(Kontoart key : temp.keySet()) .collect(Collectors.toList());
{
for(Konto k : temp.get(key))
{
output.add(k);
}
}
return output; return output;
} }
@ -78,43 +72,40 @@ public class Bank implements Serializable {
public long findMax() public long findMax()
{ {
Collection<Konto> kontenTemp = konten.values(); Collection<Konto> kontenTemp = konten.values();
// Long maxy = kontenTemp.stream().map(n -> n.getKontostand()).reduce(Long::max).get();
long max = kontenTemp.stream().map(n -> n.getKontostand()).max((a,b) -> long max = kontenTemp.stream().map(n -> n.getKontostand()).max((a,b) ->
a.compareTo(b)).get(); a.compareTo(b)).get();
return max; return max;
} }
public long findmin() public long findmin()
{ {
Collection<Konto> kontenTemp = konten.values(); Collection<Konto> kontenTemp = konten.values();
long min = 0; long min = kontenTemp.stream().map(n -> n.getKontostand()).min((a,b) ->
a.compareTo(b)).get();
for(Konto k : kontenTemp)
{
if(min > k.getKontostand())
min = k.getKontostand();
}
return min; return min;
} }
public long findaverage() public double findaverage()
{ {
Collection<Konto> kontenTemp = konten.values(); Collection<Konto> kontenTemp = konten.values();
long average = 0; double average = kontenTemp.stream().map(n -> n.getKontostand()).
int i = 0; collect(Collectors.averagingLong(a -> a));
for(Konto k : kontenTemp) return average;
}
public Collection<Konto> minus()
{ {
i++;
average += k.getKontostand();
Collection<Konto> kontenTemp = konten.values();
Collection<Konto> minus = kontenTemp.stream().filter(n -> n.getKontostand()<0)
.collect(Collectors.toList());
return minus;
} }
return average/i;
}

View File

@ -112,5 +112,24 @@ public class Banksystem {
{ {
return bank.findMax(); return bank.findMax();
} }
public long findMin()
{
return bank.findmin();
}
public double findAvg()
{
return bank.findaverage();
}
public String[] unterMinus()
{
Collection<Konto> konten = bank.minus();
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
liste[i++] = k.toString();
}
return liste;
}
} }

View File

@ -31,7 +31,8 @@ public class UI {
System.out.println("7 -> Saldo abfragen"); System.out.println("7 -> Saldo abfragen");
System.out.println("8: -> Filtering"); System.out.println("8: -> Filtering");
System.out.println("10: -> find max"); System.out.println("10: -> find max");
System.out.println("11: -> find min");
System.out.println("12: -> find avg");
System.out.println("9 -> Beenden"); System.out.println("9 -> Beenden");
System.out.println(); System.out.println();
@ -52,7 +53,9 @@ public class UI {
case 7: saldoAbfragen(); break; case 7: saldoAbfragen(); break;
case 8: filtering(); break; case 8: filtering(); break;
case 9: break mainloop; case 9: break mainloop;
case 10: findMax(); case 10: findMax(); break;
case 11: findMin(); break;
case 12: findAvg(); break;
} }
} catch (Exception e) { } catch (Exception e) {
@ -180,5 +183,16 @@ public class UI {
{ {
System.out.println(bs.findMax()); System.out.println(bs.findMax());
} }
private void findMin()
{
System.out.println(bs.findMin());
}
private void findAvg()
{
System.out.println(bs.findAvg());
}
private void unterMinus()
{
}
} }