forked from hummel/BankSystemWS23
Compare commits
No commits in common. "persistence" and "main" have entirely different histories.
persistenc
...
main
|
@ -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,8 +16,6 @@ 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();
|
||||
}
|
||||
|
||||
|
@ -52,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 = Bank.loadBankData();
|
||||
|
||||
willkommen();
|
||||
hauptmenü();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue