generated from hummel/Bank-System
Persistence hinzugefügt
parent
248c31ddd6
commit
b427dffdef
|
@ -1,5 +1,7 @@
|
|||
package de.hs_mannheim.informatik.bank;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||
|
||||
|
@ -7,7 +9,25 @@ public class Main {
|
|||
|
||||
public static void main(String[] args) {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
|
||||
// Konten laden falls vorhanden
|
||||
try {
|
||||
bs.ladeKonten();
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
System.out.println("Laden fehlgeschlagen.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
UI ui = new UI(bs);
|
||||
|
||||
// Konten speichern (Wird beim Beenden des Programms ausgeführt)
|
||||
try {
|
||||
bs.speichereKonten();
|
||||
} catch (IOException e1) {
|
||||
System.out.println("Speichern fehlgeschlagen.");
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,11 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Konto {
|
||||
import persistence.PersistenceService;
|
||||
|
||||
public class Konto implements Serializable {
|
||||
private static int kontozaehler = 0;
|
||||
private ArrayList<String> bewegungen = new ArrayList<String>();
|
||||
private int nummer;
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
import persistence.PersistenceService;
|
||||
|
||||
public class Banksystem {
|
||||
private Bank bank;
|
||||
private PersistenceService ps = new PersistenceService();
|
||||
|
||||
public Banksystem(String bankname) {
|
||||
this.bank = new Bank(bankname);
|
||||
|
@ -46,6 +52,8 @@ public class Banksystem {
|
|||
// Betrag mit 2 Nachkommastellen für den User anzeigen lassen
|
||||
String betrag_aktuell = kontostandMitKomma(k);
|
||||
k.setBewegungen(betrag_aktuell + " (+)");
|
||||
DateTimeFormatter zeitformat = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
LocalDateTime zeit = LocalDateTime.now();
|
||||
|
||||
return betrag_aktuell;
|
||||
}
|
||||
|
@ -91,6 +99,19 @@ public class Banksystem {
|
|||
return k.getBewegungen();
|
||||
}
|
||||
|
||||
public void speichereKonten() throws FileNotFoundException, IOException {
|
||||
ArrayList<Konto> konten = new ArrayList<Konto>(bank.getKontenliste());
|
||||
ps.speichereKontodaten(konten);
|
||||
}
|
||||
|
||||
public void ladeKonten() throws FileNotFoundException, ClassNotFoundException, IOException {
|
||||
ArrayList<Konto> konten = new ArrayList<Konto>();
|
||||
konten = ps.ladeKontodaten();
|
||||
for (Konto k: konten) {
|
||||
bank.addKonto(k);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getKontenliste() {
|
||||
Collection<Konto> konten = bank.getKontenliste();
|
||||
String[] liste = new String[konten.size()];
|
||||
|
@ -103,6 +124,10 @@ public class Banksystem {
|
|||
return liste;
|
||||
}
|
||||
|
||||
public Collection<Konto> getKonten() {
|
||||
return bank.getKontenliste();
|
||||
}
|
||||
|
||||
public String getBankname() {
|
||||
return bank.getName();
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ public class UI {
|
|||
}
|
||||
|
||||
System.out.println("Auf Wiedersehen!");
|
||||
|
||||
} // hauptmenü
|
||||
|
||||
|
||||
private void kontenAnzeigen() {
|
||||
String[] konten = bs.getKontenliste();
|
||||
if (konten.length > 0) {
|
||||
|
@ -71,7 +71,7 @@ public class UI {
|
|||
}
|
||||
|
||||
private void kontoEinzahlen() {
|
||||
//Kontonr und Betrag einlesen
|
||||
// Kontonr und Betrag einlesen
|
||||
System.out.println("Kontonummer: ");
|
||||
int kontonr = sc.nextInt();
|
||||
sc.nextLine();
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package persistence;
|
||||
|
||||
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;
|
||||
import java.util.Collection;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
|
||||
public class PersistenceService implements Serializable {
|
||||
|
||||
public void speichereKontodaten(ArrayList<Konto> konten) throws FileNotFoundException, IOException {
|
||||
try {
|
||||
FileOutputStream fop = new FileOutputStream("Konten.ser");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fop);
|
||||
oos.writeObject(konten);
|
||||
oos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("Speichern fehlgeschlagen!!!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Konto> ladeKontodaten() throws FileNotFoundException, IOException, ClassNotFoundException {
|
||||
ArrayList<Konto> konten = null;
|
||||
try {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Konten.ser"));
|
||||
konten = (ArrayList<Konto>) ois.readObject();
|
||||
ois.close();
|
||||
} catch (IOException e) {
|
||||
System.out.println("Laden fehlgeschlagen.");
|
||||
}
|
||||
return konten;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue