Compare commits
No commits in common. "9d4a7aca59f9df8549756c4589e2938cebc058b8" and "bc3184ce5d8da35867b5053a49fedc3c4684f353" have entirely different histories.
9d4a7aca59
...
bc3184ce5d
|
@ -1,15 +1,8 @@
|
|||
package bank;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bank implements Serializable {
|
||||
public class Bank {
|
||||
private String name;
|
||||
private ArrayList<Bankkonto> kontenliste;
|
||||
|
||||
|
@ -23,27 +16,12 @@ public class Bank implements Serializable {
|
|||
kontenliste.add(bk);
|
||||
|
||||
// Speichern Methode 2: geänderte Daten speichern
|
||||
saveBankData(); // bzw. der Einfachheit halber: alle Daten ;-)
|
||||
|
||||
return bk.getKontonummer();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
// public ArrayList<Bankkonto> getKontenliste() {
|
||||
public String[] getKontendaten() {
|
||||
// kontendaten ist ein sog. DTO = Data Transfer Object
|
||||
String[] kontendaten = new String[kontenliste.size()];
|
||||
|
||||
for (int i = 0; i < kontenliste.size(); i++) {
|
||||
kontendaten[i] = kontenliste.get(i).toString();
|
||||
}
|
||||
|
||||
return kontendaten;
|
||||
|
||||
}
|
||||
|
||||
public boolean geldEinzahlen(int kontonummer, double betrag) {
|
||||
Bankkonto bk = kontoFinden(kontonummer);
|
||||
|
@ -65,30 +43,4 @@ public class Bank implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Die folgenden Persistenz-Methoden würde man in der Praxis in eine eigene
|
||||
// Klasse auslagern.
|
||||
private void saveBankData() {
|
||||
ObjectOutputStream oos;
|
||||
try {
|
||||
oos = new ObjectOutputStream(new FileOutputStream("BankData.ser"));
|
||||
oos.writeObject(this);
|
||||
oos.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Bank loadBankData() {
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("BankData.ser"));
|
||||
return (Bank) ois.readObject();
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
System.err.println("Keine Daten gespeichert, initialisiere alle Daten neu.");
|
||||
}
|
||||
|
||||
return new Bank("Spaßkasse");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,10 @@ package bank;
|
|||
import java.util.Scanner;
|
||||
|
||||
public class BankUI {
|
||||
private static Bank bank;
|
||||
private static Bank bank = new Bank("Spaßkasse");
|
||||
private static Scanner kb = new Scanner(System.in);
|
||||
|
||||
public static void main(String[] args) {
|
||||
bank = new Bank("Spaßkasse"); //Bank.loadBankData();
|
||||
|
||||
willkommen();
|
||||
hauptmenü();
|
||||
}
|
||||
|
@ -24,7 +22,6 @@ public class BankUI {
|
|||
System.out.println("Aufgabe auswählen:");
|
||||
System.out.println("1) Konto anlegen");
|
||||
System.out.println("2) Geld einzahlen");
|
||||
System.out.println("3) Kontenliste anzeigen");
|
||||
System.out.println("9) Programm beenden");
|
||||
|
||||
System.out.print("Eingabe > ");
|
||||
|
@ -34,7 +31,6 @@ public class BankUI {
|
|||
switch (eingabe) {
|
||||
case 1 -> kontoAnlegenScreen();
|
||||
case 2 -> geldEinzahlenScreen();
|
||||
case 3 -> kontenlisteAnzeigenScreen();
|
||||
case 9 -> aufWiedersehenScreen();
|
||||
}
|
||||
|
||||
|
@ -60,14 +56,6 @@ public class BankUI {
|
|||
boolean erg = bank.geldEinzahlen(kontonummer, betrag);
|
||||
System.out.println("Geld einzahlen " + (erg?"": "nicht ") + "erfolgreich.");
|
||||
}
|
||||
|
||||
private static void kontenlisteAnzeigenScreen() {
|
||||
System.out.println("Hier sind die Konten:");
|
||||
|
||||
for (String ke : bank.getKontendaten()) {
|
||||
System.out.println(ke.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private static void aufWiedersehenScreen() {
|
||||
System.out.println("Danke für Ihren Besuch und auf baldiges Wiedersehen!");
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
package bank;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Bankkonto implements Serializable {
|
||||
public class Bankkonto {
|
||||
// sog. Geheimnisprinzip, Attribute bleiben
|
||||
// privat, Zugriff erfolgt nur über Methoden
|
||||
private String name;
|
||||
|
@ -53,9 +52,4 @@ public class Bankkonto implements Serializable {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Bankkonto [name=" + name + ", kontonummer=" + kontonummer + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue