forked from hummel/Bank-System
Compare commits
No commits in common. "main" and "main" have entirely different histories.
|
@ -1,7 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
<?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.junit.JUNIT_CONTAINER/5"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -2,15 +2,12 @@ package de.hs_mannheim.informatik.bank;
|
|||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||
import de.hs_mannheim.informatik.bank.ui.GUI;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
GUI gui = new GUI(bs);
|
||||
UI ui = new UI(bs);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -7,9 +7,7 @@ import java.util.HashMap;
|
|||
public class Bank implements Serializable {
|
||||
private String name;
|
||||
private HashMap<Integer, Konto> konten = new HashMap<>();
|
||||
private HashMap<Integer, Kunde> kunden = new HashMap<>();
|
||||
private int kontozähler;
|
||||
private int kundenzähler;
|
||||
|
||||
public Bank(String name) {
|
||||
this.name = name;
|
||||
|
@ -40,10 +38,5 @@ public class Bank implements Serializable {
|
|||
public Konto findeKonto(int kontonummer) {
|
||||
return konten.get(kontonummer);
|
||||
}
|
||||
|
||||
public int addKunde(String vName, String nName, int alter, String wohnort, int kontonummer) {
|
||||
Kunde kunde = new Kunde(vName, nName, alter, wohnort, konten.get(kontonummer), ++kundenzähler);
|
||||
return kunde.getKundennummer();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
public class Kunde implements Serializable{
|
||||
private String vName;
|
||||
private String nName;
|
||||
private int alter;
|
||||
private String wohnort;
|
||||
private int kundenNummer;
|
||||
private ArrayList<Konto> konten;
|
||||
|
||||
|
||||
public Kunde(String vName, String nName, int alter, String wohnort, Konto konto, int kundenNummer) {
|
||||
this.vName = vName;
|
||||
this.nName = nName;
|
||||
this.alter = alter;
|
||||
this.wohnort = wohnort;
|
||||
this.konten.add(konto);
|
||||
this.kundenNummer = kundenNummer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.vName + ";" + this.nName + ";" + this.alter + ";" + this.wohnort + ";";
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getKundennummer() {
|
||||
|
||||
return this.kundenNummer;
|
||||
}
|
||||
}
|
|
@ -16,11 +16,6 @@ public class Banksystem {
|
|||
else
|
||||
this.bank = new Bank(bankname);
|
||||
}
|
||||
|
||||
public int kundeAnlegen(String vName, String nName, int alter, String wohnort, int kontonummer) {
|
||||
int kundennummer = bank.addKunde(vName, nName, alter, wohnort, kontonummer);
|
||||
return kundennummer;
|
||||
}
|
||||
|
||||
public int kontoAnlegen(String name, int auswahl) throws Exception {
|
||||
int kontonummer = bank.addKonto(name, auswahl);
|
||||
|
@ -97,10 +92,4 @@ public class Banksystem {
|
|||
return konto.berechneSaldo(anzahl);
|
||||
}
|
||||
|
||||
public void systemwiederherstellung() throws ClassNotFoundException, Exception{
|
||||
this.bank = (Bank) Persistenz.ladeBankDaten(bank.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ import java.io.FileOutputStream;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import jdk.internal.misc.FileSystemOption;
|
||||
|
||||
public class Persistenz {
|
||||
private static final String BANK_DATEI = "-bank-data.ser";
|
||||
|
||||
|
@ -16,16 +14,12 @@ public class Persistenz {
|
|||
}
|
||||
|
||||
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 Exception, 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,78 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.ui;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
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;
|
||||
//import sun.util.resources.cldr.ext.CurrencyNames_en_RW;
|
||||
|
||||
public class GUI implements ActionListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Banksystem bs;
|
||||
private JTextField eingabe;
|
||||
private JTextArea ausgabe;
|
||||
private JButton ok;
|
||||
private JButton kontenAnzeigen;
|
||||
|
||||
public GUI(Banksystem bs) {
|
||||
JFrame jFrame = new JFrame(bs.getBankname());
|
||||
FlowLayout experimentLayout = new FlowLayout();
|
||||
|
||||
jFrame.setLayout(experimentLayout);
|
||||
this.bs = bs;
|
||||
/*this.setTitle(bs.getBankname());
|
||||
this.setSize(600, 600);
|
||||
this.setDefaultCloseOperation(GUI.EXIT_ON_CLOSE);*/
|
||||
jFrame.setSize(600, 600);
|
||||
|
||||
|
||||
JButton button1 = new JButton("Konten anzeigen");
|
||||
JButton button2 = new JButton("Konto anlegen");
|
||||
JButton button3 = new JButton("Geld einzahlen");
|
||||
JButton button4 = new JButton("Geld auszahlen");
|
||||
|
||||
jFrame.getContentPane().add(button1);
|
||||
jFrame.getContentPane().add(button2);
|
||||
jFrame.getContentPane().add(button3);
|
||||
jFrame.getContentPane().add(button4);
|
||||
|
||||
eingabe = new JTextField(20);
|
||||
|
||||
ausgabe = new JTextArea(5, 20);
|
||||
ausgabe.setLineWrap(true);
|
||||
ausgabe.setWrapStyleWord(true);
|
||||
|
||||
JScrollPane sp = new JScrollPane(ausgabe);
|
||||
|
||||
button1.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
UI.kontenAnzeigen(); // Hier bin Ich das letzte Mal
|
||||
}
|
||||
});
|
||||
|
||||
jFrame.setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ausgabe.append(eingabe.getText() + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,6 @@ public class UI {
|
|||
System.out.println();
|
||||
System.out.println("--------");
|
||||
System.out.println("Hauptmenü");
|
||||
System.out.println("0 -> Kunden Account anlegen");
|
||||
System.out.println("1 -> Konten anzeigen");
|
||||
System.out.println("2 -> Konto anlegen");
|
||||
System.out.println("3 -> Geld einzahlen");
|
||||
|
@ -31,7 +30,6 @@ public class UI {
|
|||
System.out.println("7 -> Saldo abfragen");
|
||||
|
||||
System.out.println("9 -> Beenden");
|
||||
System.out.println("10 -> GUI verwenden");
|
||||
System.out.println();
|
||||
|
||||
System.out.print("> ");
|
||||
|
@ -40,16 +38,16 @@ public class UI {
|
|||
|
||||
try {
|
||||
switch(input) {
|
||||
case 0: kundeAnlegen(); break;
|
||||
case 1: kontenAnzeigen(); break;
|
||||
case 2: kontoAnlegen();break;
|
||||
case 2:
|
||||
kontoAnlegen();
|
||||
break;
|
||||
case 3: geldEinzahlen(); break;
|
||||
case 4: geldAuszahlen(); break;
|
||||
case 5: kontoauszugDrucken(); break;
|
||||
case 6: überweisungBeauftragen(); break;
|
||||
case 7: saldoAbfragen(); break;
|
||||
case 9: break mainloop;
|
||||
case 10: guiAusführen(); break;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
@ -62,27 +60,7 @@ public class UI {
|
|||
|
||||
} // hauptmenü
|
||||
|
||||
private void kundeAnlegen() throws Exception{
|
||||
System.out.println("Bitte geben sie ihren Vornamen ein: ");
|
||||
String vName = sc.nextLine();
|
||||
|
||||
System.out.println("Bitte geben sie ihren Nachnamen ein: ");
|
||||
String nName = sc.nextLine();
|
||||
|
||||
System.out.println("Bitte geben sie ihr Alter ein: ");
|
||||
int alter = Integer.parseInt(sc.nextLine());
|
||||
|
||||
System.out.println("Bitte geben sie ihren Wohnort ein: ");
|
||||
String wohnort = sc.nextLine();
|
||||
|
||||
System.out.println("Möchten Sie ein Sparkonto (1) oder ein Girokonto (2) anlegen?");
|
||||
int auswahl = Integer.parseInt(sc.nextLine());
|
||||
int kontonummer = bs.kontoAnlegen(vName+nName, auswahl);
|
||||
int kundennummer = bs.kundeAnlegen(vName, nName, alter, wohnort, kontonummer);
|
||||
System.out.println("Kunde mit mit der Kundennummer " + kundennummer + "und mit der Kontonummer " + kontonummer + "neu angelegt");
|
||||
}
|
||||
|
||||
void kontenAnzeigen() {
|
||||
private void kontenAnzeigen() {
|
||||
String[] konten = bs.getKontenliste();
|
||||
if (konten.length > 0) {
|
||||
System.out.println("Folgende Konten sind aktuell verfügbar:");
|
||||
|
@ -105,7 +83,7 @@ public class UI {
|
|||
System.out.println("Konto mit der Nummer " + kontonummer + " neu angelegt.");
|
||||
}
|
||||
|
||||
private void geldEinzahlen() {
|
||||
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());
|
||||
|
@ -114,23 +92,12 @@ public class UI {
|
|||
|
||||
System.out.print("Bitte den gewünschten Betrag eingeben: ");
|
||||
double betrag = Double.parseDouble(sc.nextLine());
|
||||
try {
|
||||
|
||||
long neuerKontostand = bs.geldEinzahlen(kontonummer, (long)betrag * 100);
|
||||
|
||||
System.out.printf("Einzahlung erfolgreich, neuer Kontostand = %.2f Euro", (neuerKontostand / 100.0));
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println("Einzahlung nicht erfolgreich, wurde nicht gespeichert");
|
||||
try {
|
||||
bs.systemwiederherstellung();
|
||||
}
|
||||
catch (Exception cnfe) {
|
||||
System.err.println("Fehler aufgetreten(ClassNotFoundException)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void geldAuszahlen() throws Exception {
|
||||
System.out.println("Geld auszahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
|
@ -189,11 +156,5 @@ 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 guiAusführen() {
|
||||
GUI gui = new GUI(bs);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue