New: changed forEach to lambda

in kontoliste und kontoauszug
gui
Caner 2022-12-05 16:01:20 +01:00
parent 9423e4fe7a
commit b837bddaa5
3 changed files with 34 additions and 14 deletions

View File

@ -2,8 +2,9 @@ package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class Konto implements Serializable {
public class Konto implements Serializable, Comparable<Konto>{
private static final long serialVersionUID = 1L;
@ -38,14 +39,11 @@ public class Konto implements Serializable {
}
public String[] getKontobewegungen() {
String[] auflistung = new String[kontobewegungen.size()];
int i = 0;
for (Kontobewegung kb : kontobewegungen) {
auflistung[i++] = kb.toString();
}
String[] bewegungen = kontobewegungen.stream().map(b -> b.toString()).toArray(String[]::new);
return bewegungen;
return auflistung;
}
public long berechneSaldo(int anzahl) {
@ -83,5 +81,13 @@ public class Konto implements Serializable {
return stand;
}
@Override
public int compareTo(Konto o) {
Konto k = (Konto) o;
return (int) (this.getKontostand() - k.getKontostand());
}
}

View File

@ -3,6 +3,8 @@ package de.hs_mannheim.informatik.bank.facade;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.TreeSet;
import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Depot;
@ -61,12 +63,24 @@ public class Banksystem {
public String[] getKontenlisteForKunde(){
Collection<Konto> konten = bank.getKundenKonto(currentKunde);
//TreeSet<Konto> kontenSet = new TreeSet<Konto>(konten);
List<Konto> kontenList = (List<Konto>) konten;
String[] liste = new String[konten.size()];
int i = 0;
for (Konto k : konten) {
liste[i++] = k.toString();
// kontenSet.stream().forEach(
// konto -> {
// liste[kontenSet.headSet(konto).size()] = konto.toString(); // treeset methode
// }
// );
kontenList.stream().forEach(
konto -> {
liste[kontenList.indexOf(konto)] = konto.toString(); // list methode
}
);
return liste;

View File

@ -46,17 +46,17 @@ public class HauptmenüFrame implements ActionListener {
panel.add(label2);
this.button = new JButton("Neuen Kunden anlegen");
button.setBounds(15, 80, 250, 25);
button.setBounds(17, 80, 250, 25);
button.addActionListener(this);
panel.add(button);
this.button2 = new JButton("Bei Kunden einloggen");
button2.setBounds(15, 110, 250, 25);
button2.setBounds(17, 110, 250, 25);
button2.addActionListener(this);
panel.add(button2);
this.button3 = new JButton("Beenden");
button3.setBounds(15, 140, 250, 25);
button3.setBounds(17, 140, 250, 25);
button3.addActionListener(this);
panel.add(button3);