Compare commits
No commits in common. "guiExample" and "main" have entirely different histories.
guiExample
...
main
|
@ -1,21 +1,13 @@
|
|||
package de.hs_mannheim.informatik.bank;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
import de.hs_mannheim.informatik.bank.gui.KontoAnlegenFrame;
|
||||
import de.hs_mannheim.informatik.bank.gui.KontoListingFrame;
|
||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
// UI ui = new UI(bs);
|
||||
|
||||
KontoAnlegenFrame kaf = new KontoAnlegenFrame(bs);
|
||||
kaf.setVisible(true);
|
||||
|
||||
|
||||
KontoListingFrame klf = new KontoListingFrame(bs);
|
||||
klf.setVisible(true);
|
||||
UI ui = new UI(bs);
|
||||
}
|
||||
|
||||
}
|
|
@ -73,10 +73,4 @@ public class Konto implements Serializable {
|
|||
return saldo;
|
||||
}
|
||||
|
||||
public void rollback() {
|
||||
Kontobewegung kbw = kontobewegungen.get(kontobewegungen.size()-1);
|
||||
stand += kbw.getBetrag() *-1;
|
||||
kontobewegungen.remove(kontobewegungen.size()-1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
|
@ -11,21 +10,14 @@ import de.hs_mannheim.informatik.bank.infrastructure.Persistenz;
|
|||
public class Banksystem {
|
||||
private Bank bank;
|
||||
|
||||
public Banksystem(String bankname) {
|
||||
public Banksystem(String bankname) throws Exception {
|
||||
if (Persistenz.sindDatenGespeichert(bankname))
|
||||
try {
|
||||
this.bank = (Bank) Persistenz.ladeBankDaten(bankname);
|
||||
|
||||
return;
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
// Hier loggen wir die Exception und starten einfach mit einem leeren System.
|
||||
System.err.println("Persistierte Daten konnten nicht geladen werden.");
|
||||
}
|
||||
|
||||
this.bank = new Bank(bankname);
|
||||
this.bank = (Bank) Persistenz.ladeBankDaten(bankname);
|
||||
else
|
||||
this.bank = new Bank(bankname);
|
||||
}
|
||||
|
||||
public int kontoAnlegen(String name, int auswahl) throws IOException {
|
||||
public int kontoAnlegen(String name, int auswahl) throws Exception {
|
||||
int kontonummer = bank.addKonto(name, auswahl);
|
||||
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
@ -49,21 +41,16 @@ public class Banksystem {
|
|||
return bank.getName();
|
||||
}
|
||||
|
||||
public long geldEinzahlen(int kontonummer, long betrag) throws IOException {
|
||||
public long geldEinzahlen(int kontonummer, long betrag) throws Exception {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
konto.einzahlen(betrag, "Einzahlung am Schalter", "Einzahlung", konto.getInhaber());
|
||||
|
||||
try {
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
} catch (IOException ioe) {
|
||||
konto.rollback();
|
||||
throw ioe;
|
||||
}
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
return konto.getKontostand();
|
||||
}
|
||||
|
||||
public boolean geldAuszahlen(int kontonummer, long betrag) throws IOException {
|
||||
public boolean geldAuszahlen(int kontonummer, long betrag) throws Exception {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
|
||||
boolean erg = konto.auszahlen(betrag, "Auszahlung am Schalter", "Auszahlung", konto.getInhaber());
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
||||
public class KontoAnlegenFrame extends JFrame implements ActionListener {
|
||||
private JTextField eingabe;
|
||||
private JTextArea ausgabe;
|
||||
private JButton ok;
|
||||
|
||||
private Banksystem bs;
|
||||
|
||||
public KontoAnlegenFrame(Banksystem bs) {
|
||||
this.bs = bs;
|
||||
|
||||
this.setTitle(bs.getBankname());
|
||||
this.setSize(300, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
eingabe = new JTextField(20);
|
||||
|
||||
ausgabe = new JTextArea(5, 20);
|
||||
ausgabe.setLineWrap(true);
|
||||
ausgabe.setWrapStyleWord(true);
|
||||
|
||||
// Die Ausgabe automatisch scrollbar machen, wenn Sie nicht
|
||||
// mehr auf den Bildschirm passen sollte.
|
||||
JScrollPane sp = new JScrollPane(ausgabe);
|
||||
|
||||
ok = new JButton("Konto anlegen");
|
||||
ok.addActionListener(this);
|
||||
|
||||
// Container cp = this.getContentPane();
|
||||
this.add(eingabe, "North");
|
||||
this.add(sp, "Center");
|
||||
this.add(ok, "South");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Konto anlegen...");
|
||||
|
||||
try {
|
||||
int knr = bs.kontoAnlegen(eingabe.getText(), 1);
|
||||
|
||||
this.ausgabe.append("Neues Konto angelegt: " + knr + "\n");
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
||||
public class KontoListingFrame extends JFrame implements ActionListener {
|
||||
private JTextField eingabe;
|
||||
private JTextArea ausgabe;
|
||||
private JButton ok;
|
||||
|
||||
private Banksystem bs;
|
||||
|
||||
public KontoListingFrame(Banksystem bs) {
|
||||
this.bs = bs;
|
||||
|
||||
this.setTitle(bs.getBankname());
|
||||
this.setSize(300, 300);
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
eingabe = new JTextField(20);
|
||||
|
||||
ausgabe = new JTextArea(5, 20);
|
||||
ausgabe.setLineWrap(true);
|
||||
ausgabe.setWrapStyleWord(true);
|
||||
|
||||
// Die Ausgabe automatisch scrollbar machen, wenn Sie nicht
|
||||
// mehr auf den Bildschirm passen sollte.
|
||||
JScrollPane sp = new JScrollPane(ausgabe);
|
||||
|
||||
ok = new JButton("Kontenliste abrufen");
|
||||
ok.addActionListener(this);
|
||||
|
||||
// Container cp = this.getContentPane();
|
||||
// this.add(eingabe, "North");
|
||||
this.add(sp, "Center");
|
||||
this.add(ok, "South");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Kontenliste abrufen...");
|
||||
|
||||
ausgabe.setText("");
|
||||
String[] konten = bs.getKontenliste();
|
||||
|
||||
for (String konto : konten) {
|
||||
ausgabe.append(konto + "\n");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,6 @@ package de.hs_mannheim.informatik.bank.infrastructure;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
|
@ -14,13 +13,13 @@ public class Persistenz {
|
|||
return new File(name + BANK_DATEI).exists();
|
||||
}
|
||||
|
||||
public static void speichereBankDaten(Object bank, String name) throws IOException {
|
||||
public static void speichereBankDaten(Object bank, String name) throws Exception {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + BANK_DATEI));
|
||||
oos.writeObject(bank);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
public static Object ladeBankDaten(String name) throws IOException, ClassNotFoundException {
|
||||
public static Object ladeBankDaten(String name) throws Exception {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + BANK_DATEI));
|
||||
Object bank = ois.readObject();
|
||||
ois.close();
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.hs_mannheim.informatik.bank.tui;
|
||||
package de.hs_mannheim.informatik.bank.ui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
@ -50,6 +49,7 @@ public class UI {
|
|||
case 7: saldoAbfragen(); break;
|
||||
case 9: break mainloop;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getLocalizedMessage());
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class UI {
|
|||
}
|
||||
}
|
||||
|
||||
private void kontoAnlegen() throws IOException {
|
||||
private void kontoAnlegen() throws Exception {
|
||||
System.out.println("Bitte den Namen des Kontoinhabers angeben: ");
|
||||
String name = sc.nextLine();
|
||||
|
||||
|
@ -83,40 +83,22 @@ public class UI {
|
|||
System.out.println("Konto mit der Nummer " + kontonummer + " neu angelegt.");
|
||||
}
|
||||
|
||||
private void geldEinzahlen() throws IOException {
|
||||
int kontonummer = 0;
|
||||
double betrag = 0;
|
||||
boolean ok = false;
|
||||
private void geldEinzahlen() throws Exception {
|
||||
System.out.println("Geld einzahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
||||
|
||||
do {
|
||||
System.out.println("Geld einzahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
// optional prüfen, ob Konto existiert
|
||||
|
||||
try {
|
||||
kontonummer = Integer.parseInt(sc.nextLine());
|
||||
// optional prüfen, ob Konto existiert
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.err.println("Kontonummer muss eine Zahl sein, bitte Eingabe wiederholen!");
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.print("Bitte den gewünschten Betrag eingeben: ");
|
||||
try {
|
||||
betrag = Double.parseDouble(sc.nextLine());
|
||||
} catch (NumberFormatException nfe) {
|
||||
System.err.println("Betrag muss eine Kommazahl sein, bitte Eingabe wiederholen!");
|
||||
continue;
|
||||
}
|
||||
|
||||
ok = true;
|
||||
} while(!ok);
|
||||
System.out.print("Bitte den gewünschten Betrag eingeben: ");
|
||||
double betrag = Double.parseDouble(sc.nextLine());
|
||||
|
||||
long neuerKontostand = bs.geldEinzahlen(kontonummer, (long)betrag * 100);
|
||||
|
||||
System.out.printf("Einzahlung erfolgreich, neuer Kontostand = %.2f Euro", (neuerKontostand / 100.0));
|
||||
}
|
||||
|
||||
private void geldAuszahlen() throws IOException {
|
||||
private void geldAuszahlen() throws Exception {
|
||||
System.out.println("Geld auszahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
Loading…
Reference in New Issue