Compare commits
5 Commits
Author | SHA1 | Date |
---|---|---|
nikow | b33f0340f7 | |
nikow | 5820c0b754 | |
nikow | e6cb04da0e | |
nikow | 1f4ce06b09 | |
nikow | 9d2cdf76da |
|
@ -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.junit.JUNIT_CONTAINER/5"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -2,12 +2,15 @@ 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,7 +7,9 @@ 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;
|
||||
|
@ -39,4 +41,9 @@ public class Bank implements Serializable {
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
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;
|
||||
}
|
||||
}
|
|
@ -17,6 +17,11 @@ public class Banksystem {
|
|||
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);
|
||||
|
||||
|
@ -92,4 +97,10 @@ public class Banksystem {
|
|||
return konto.berechneSaldo(anzahl);
|
||||
}
|
||||
|
||||
public void systemwiederherstellung() throws ClassNotFoundException, Exception{
|
||||
this.bank = (Bank) Persistenz.ladeBankDaten(bank.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ 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";
|
||||
|
||||
|
@ -14,12 +16,16 @@ 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 {
|
||||
public static Object ladeBankDaten(String name) throws Exception, ClassNotFoundException {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + BANK_DATEI));
|
||||
Object bank = ois.readObject();
|
||||
ois.close();
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
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,6 +21,7 @@ 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");
|
||||
|
@ -30,6 +31,7 @@ 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("> ");
|
||||
|
@ -38,16 +40,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) {
|
||||
|
@ -60,7 +62,27 @@ public class UI {
|
|||
|
||||
} // hauptmenü
|
||||
|
||||
private void kontenAnzeigen() {
|
||||
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() {
|
||||
String[] konten = bs.getKontenliste();
|
||||
if (konten.length > 0) {
|
||||
System.out.println("Folgende Konten sind aktuell verfügbar:");
|
||||
|
@ -83,7 +105,7 @@ public class UI {
|
|||
System.out.println("Konto mit der Nummer " + kontonummer + " neu angelegt.");
|
||||
}
|
||||
|
||||
private void geldEinzahlen() throws Exception {
|
||||
private void geldEinzahlen() {
|
||||
System.out.println("Geld einzahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
||||
|
@ -92,11 +114,22 @@ 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");
|
||||
|
@ -157,4 +190,10 @@ public class UI {
|
|||
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