forked from hummel/Bank-System
Exceptions
parent
9d2cdf76da
commit
1f4ce06b09
|
@ -92,4 +92,9 @@ 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();
|
||||
|
|
|
@ -83,7 +83,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 +92,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");
|
||||
|
|
Loading…
Reference in New Issue