New: implemented examples from übung 8
parent
2699599f53
commit
473aa0c1be
|
@ -4,7 +4,8 @@ import java.io.IOException;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Depot;
|
||||
|
@ -76,6 +77,63 @@ public class Banksystem {
|
|||
|
||||
}
|
||||
|
||||
public void mapKontoToString(){
|
||||
|
||||
HashMap<Integer, Konto> konten = bank.getKonten();
|
||||
|
||||
List<String> kontenList = konten.values().stream()
|
||||
.map(konto -> konto.toString())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
kontenList.stream().forEach(s -> System.out.println(s));
|
||||
|
||||
}
|
||||
|
||||
public void mapKundeToString(){
|
||||
|
||||
HashMap<Integer, Kunde> kunden = bank.getKundenMap();
|
||||
|
||||
List<String> kundenList = kunden.values().stream()
|
||||
.map(kunde -> kunde.toString())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
kundenList.stream().forEach(s -> System.out.println(s));
|
||||
|
||||
}
|
||||
|
||||
public double getAllBalances(){
|
||||
|
||||
Collection<Konto> kontenValues = bank.getKonten().values();
|
||||
|
||||
Stream<Konto> kontenStream = kontenValues.stream();
|
||||
|
||||
double sum = kontenStream.mapToDouble(konto -> konto.getKontostand()).sum();
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void getMinMaxAvgBalances(){
|
||||
|
||||
Collection<Konto> kontenValues = bank.getKonten().values();
|
||||
|
||||
Stream<Konto> kontenStream = kontenValues.stream();
|
||||
|
||||
double min = kontenStream.mapToDouble(konto -> konto.getKontostand()).min().getAsDouble();
|
||||
|
||||
kontenStream = kontenValues.stream();
|
||||
|
||||
double max = kontenStream.mapToDouble(konto -> konto.getKontostand()).max().getAsDouble();
|
||||
|
||||
kontenStream = kontenValues.stream();
|
||||
|
||||
double avg = kontenStream.mapToDouble(konto -> konto.getKontostand()).average().getAsDouble();
|
||||
|
||||
System.out.println("Min: " + (min / 100) + " Max: " + (max /100) + " Avg: " + (avg / 100));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String[] getAktienliste() {
|
||||
|
||||
Collection<String> aktien = bank.getAktienliste();
|
||||
|
|
|
@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.bank.ui;
|
|||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Scanner;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Kontoart;
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
@ -29,6 +30,10 @@ public class UI {
|
|||
System.out.println("3 -> Konten anzeigen");
|
||||
System.out.println("4 -> Konto auswählen");
|
||||
System.out.println("6 -> Negativ konten anzeigen");
|
||||
System.out.println("7 -> Geldbestand der Bank anzeigen");
|
||||
System.out.println("8 -> Min/Max/Avg Kontostände");
|
||||
System.out.println("9 -> Konten anzeigen");
|
||||
System.out.println("10 -> Kunden anzeigen");
|
||||
|
||||
System.out.println("5 -> Beenden");
|
||||
System.out.println();
|
||||
|
@ -57,6 +62,18 @@ public class UI {
|
|||
case 6:
|
||||
negativKontenAnzeigen();
|
||||
break;
|
||||
case 7:
|
||||
geldbestandAnzeigen();
|
||||
break;
|
||||
case 8:
|
||||
minMaxAvgKontostände();
|
||||
break;
|
||||
case 9:
|
||||
mapKontenAnzeigen();
|
||||
break;
|
||||
case 10:
|
||||
mapKundenAnzeigen();
|
||||
break;
|
||||
|
||||
case 5:
|
||||
break mainloop;
|
||||
|
@ -74,6 +91,34 @@ public class UI {
|
|||
|
||||
|
||||
|
||||
private void mapKundenAnzeigen() {
|
||||
|
||||
System.out.println("Kunden anzeigen: ");
|
||||
bs.mapKundeToString();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void mapKontenAnzeigen() {
|
||||
|
||||
System.out.println("Konten anzeigen: ");
|
||||
bs.mapKontoToString();
|
||||
|
||||
}
|
||||
|
||||
private void minMaxAvgKontostände() {
|
||||
|
||||
System.out.println("Min/Max/Avg Kontostände: ");
|
||||
bs.getMinMaxAvgBalances();
|
||||
|
||||
}
|
||||
|
||||
private void geldbestandAnzeigen() {
|
||||
|
||||
System.out.println("Geldbestand der Bank: " + (bs.getAllBalances() / 100) + "€");
|
||||
|
||||
}
|
||||
|
||||
private void negativKontenAnzeigen() {
|
||||
|
||||
System.out.println("Negativ Konten: ");
|
||||
|
@ -189,7 +234,9 @@ public class UI {
|
|||
|
||||
System.out.println("Sie haben aktuell folgende Konten zur Verfügung:");
|
||||
|
||||
Arrays.stream(konten).forEach(System.out::println);
|
||||
Stream<String> stream = Arrays.stream(konten);
|
||||
|
||||
stream.forEach(s -> System.out.println(s));
|
||||
|
||||
|
||||
} else {
|
||||
|
@ -528,10 +575,10 @@ public class UI {
|
|||
|
||||
try {
|
||||
|
||||
if (kontobewegungen.length > 0)
|
||||
for (String kb : kontobewegungen) {
|
||||
System.out.println(kb);
|
||||
}
|
||||
Stream<String> stream = Arrays.stream(kontobewegungen);
|
||||
|
||||
stream.forEach(System.out::println);
|
||||
|
||||
running = false;
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
Loading…
Reference in New Issue