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

View File

@ -112,5 +112,24 @@ public class Banksystem {
{
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("8: -> Filtering");
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();
@ -52,7 +53,9 @@ public class UI {
case 7: saldoAbfragen(); break;
case 8: filtering(); break;
case 9: break mainloop;
case 10: findMax();
case 10: findMax(); break;
case 11: findMin(); break;
case 12: findAvg(); break;
}
} catch (Exception e) {
@ -180,5 +183,16 @@ public class UI {
{
System.out.println(bs.findMax());
}
private void findMin()
{
System.out.println(bs.findMin());
}
private void findAvg()
{
System.out.println(bs.findAvg());
}
private void unterMinus()
{
}
}