DexterHK 2022-12-11 14:21:18 +01:00
parent 3d8e7a0f1b
commit 51e5225a68
8 changed files with 143 additions and 6 deletions

11
.project 100644
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Bank-System</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,13 @@
package de.hs_mannheim.informatik.bank;
public class Testobject01 {
public static void main(String[] args)
{
}
}

View File

@ -1,8 +1,16 @@
package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.LongSupplier;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.stream.Stream;
public class Bank implements Serializable {
private String name;
@ -43,5 +51,71 @@ public class Bank implements Serializable {
public Konto findeKonto(int kontonummer) {
return konten.get(kontonummer);
}
public Collection<Konto> filtering(int x)
{
Collection<Konto> kontenTemp = konten.values();
Map<Kontoart, List<Konto>> temp = kontenTemp.stream().collect(
Collectors.groupingBy(n -> n.getKontoart()));
switch(x)
{
case 1: return temp.get(Kontoart.Sparkonto);
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);
}
}
return output;
}
}
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();
}
return min;
}
public long findaverage()
{
Collection<Konto> kontenTemp = konten.values();
long average = 0;
int i = 0;
for(Konto k : kontenTemp)
{
i++;
average += k.getKontostand();
}
return average/i;
}
}

View File

@ -7,6 +7,7 @@ public class Girokonto extends Konto implements Serializable {
public Girokonto(String inhaber, int kontozähler) {
super(inhaber, kontozähler);
this.k = Kontoart.Girokonto;
}
public boolean überweise(Girokonto ziel, long betrag, String zweck) {

View File

@ -7,7 +7,7 @@ public class Konto implements Serializable {
private int nummer;
protected long stand = 0;
private String inhaber;
protected Kontoart k = Kontoart.Sparkonto;
protected ArrayList<Kontobewegung> kontobewegungen;
public Konto(String inhaber, int kontozähler) {
@ -72,5 +72,9 @@ public class Konto implements Serializable {
return saldo;
}
public Kontoart getKontoart()
{
return k;
}
}

View File

@ -1,6 +1,9 @@
package de.hs_mannheim.informatik.bank.facade;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Girokonto;
@ -92,5 +95,22 @@ public class Banksystem {
return konto.berechneSaldo(anzahl);
}
public String[] filtering(int x)
{
Collection<Konto> konten = bank.filtering(x);
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
liste[i++] = k.toString();
}
return liste;
}
public long findMax()
{
return bank.findMax();
}
}

View File

@ -29,6 +29,8 @@ public class UI {
System.out.println("5 -> Kontoauszug drucken");
System.out.println("6 -> Überweisung beauftragen");
System.out.println("7 -> Saldo abfragen");
System.out.println("8: -> Filtering");
System.out.println("10: -> find max");
System.out.println("9 -> Beenden");
System.out.println();
@ -48,7 +50,9 @@ public class UI {
case 5: kontoauszugDrucken(); break;
case 6: überweisungBeauftragen(); break;
case 7: saldoAbfragen(); break;
case 8: filtering(); break;
case 9: break mainloop;
case 10: findMax();
}
} catch (Exception e) {
@ -162,5 +166,19 @@ public class UI {
long saldo = bs.saldoBestimmen(konto, anzahl);
System.out.printf("Der Saldo nach %d Kontobewegungen beträgt %.2f Euro.%n", anzahl, (saldo/100d));
}
private void filtering()
{
int input = Integer.parseInt(sc.nextLine());
String[] output = bs.filtering(input);
for(int i = 0;i<output.length;i++)
{
System.out.println(output[i]);
}
}
private void findMax()
{
System.out.println(bs.findMax());
}
}