save and load works
parent
68f56c1308
commit
6e00075e9f
Binary file not shown.
|
@ -5,7 +5,7 @@ import de.hs_mannheim.informatik.bank.ui.UI;
|
|||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
UI ui = new UI(bs);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,33 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.File;
|
||||
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.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class Bank {
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
||||
public class Bank implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private Konto k;
|
||||
// private Banksystem bsy;
|
||||
private String name;
|
||||
private HashMap<Integer, Konto> konten = new HashMap<>();
|
||||
|
||||
|
||||
public Bank(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -31,8 +46,8 @@ public class Bank {
|
|||
|
||||
public long geldWirdInDerBankAngelegt(int kontoNummer, long geldBetrag) {
|
||||
k = getKonto(kontoNummer);
|
||||
k.setStand(k.getStand()+geldBetrag);
|
||||
k.setKontoAktivietetenString(k.getKontoAktivietetenString()+ getDatum() + " " + geldBetrag+",");
|
||||
k.setStand(k.getStand() + geldBetrag);
|
||||
k.setKontoAktivietetenString(k.getKontoAktivietetenString() + getDatum() + " " + geldBetrag + ",");
|
||||
return k.getStand();
|
||||
}
|
||||
|
||||
|
@ -44,12 +59,12 @@ public class Bank {
|
|||
public String geldAbhebenBank(int kontoNummer, long geldAbgehoben) {
|
||||
k = getKonto(kontoNummer);
|
||||
|
||||
if(k.getStand() < geldAbgehoben) {
|
||||
if (k.getStand() < geldAbgehoben) {
|
||||
return "Sie haben zu wenig Geld auf ihrem Konto";
|
||||
}
|
||||
|
||||
k.setStand(k.getStand()-geldAbgehoben);
|
||||
k.setKontoAktivietetenString(k.getKontoAktivietetenString()+ getDatum() +" -"+geldAbgehoben+",");
|
||||
k.setStand(k.getStand() - geldAbgehoben);
|
||||
k.setKontoAktivietetenString(k.getKontoAktivietetenString() + getDatum() + " -" + geldAbgehoben + ",");
|
||||
return "Sie haben" + geldAbgehoben + "Euro abgehoben";
|
||||
}
|
||||
|
||||
|
@ -71,4 +86,5 @@ public class Bank {
|
|||
String[] auzügeStrings = k.getKontoAktivietetenString().split(",");
|
||||
return auzügeStrings;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import javax.lang.model.element.NestingKind;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Konto {
|
||||
public class Konto implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static int kontozähler = 0;
|
||||
|
||||
|
@ -43,4 +48,6 @@ public class Konto {
|
|||
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + ", Kontostand=" + stand + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,12 @@ public class BankSystemTest {
|
|||
}
|
||||
|
||||
|
||||
/* public void testGeldEinzahlenAPI(){
|
||||
bs.addKonto(k1);
|
||||
float geldSehen = bSys.geldEinzahlen(1000, 100);
|
||||
float testLookMoney = 100;
|
||||
assertEquals(geldSehen, testLookMoney);
|
||||
}*/
|
||||
@Test
|
||||
public void testAbhebenZuWenigGeld() {
|
||||
Bank bs = new Bank("Volksbank");
|
||||
Konto k = new Konto("Müller");
|
||||
bs.addKonto(k);
|
||||
String test = "Sie haben zu wenig Geld auf ihrem Konto";
|
||||
assertEquals(bs.geldAbhebenBank(1000, 300), test);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,22 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
import persistence.Persistenc;
|
||||
|
||||
public class Banksystem {
|
||||
private Bank bank;
|
||||
|
||||
private Persistenc per = new Persistenc();
|
||||
public Banksystem(String bankname) {
|
||||
this.bank = new Bank(bankname);
|
||||
}
|
||||
|
@ -54,4 +63,15 @@ public class Banksystem {
|
|||
String[] auszügeStrings = bank.getAuszüge(kontoNummer);
|
||||
return auszügeStrings;
|
||||
}
|
||||
|
||||
public void saveKonten() throws Exception {
|
||||
per.saveKontos(bank);
|
||||
|
||||
}
|
||||
|
||||
public void loadKonten() throws Exception {
|
||||
bank = per.load();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ public class UI {
|
|||
private Banksystem bs;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
public UI(Banksystem bs) {
|
||||
public UI(Banksystem bs) throws Exception {
|
||||
this.bs = bs;
|
||||
hauptmenue();
|
||||
}
|
||||
|
||||
private void hauptmenue() {
|
||||
private void hauptmenue() throws Exception{
|
||||
System.out.println("Willkommen bei der " + bs.getBankname() + "!");
|
||||
|
||||
mainloop:
|
||||
|
@ -28,6 +28,7 @@ public class UI {
|
|||
System.out.println("4 -> Konto abfragen");
|
||||
System.out.println("5 -> Geld abheben");
|
||||
System.out.println("6 -> Kontoauszüge ausgeben");
|
||||
System.out.println("7 -> Konten laden");
|
||||
System.out.println("9 -> Beenden");
|
||||
System.out.println();
|
||||
|
||||
|
@ -42,13 +43,24 @@ public class UI {
|
|||
case 4: kontoAbfragen(); break;
|
||||
case 5: geldAbheben(); break;
|
||||
case 6: kontoauszügeAnsugeben(); break;
|
||||
case 7: kontenLaden(); break;
|
||||
case 9: break mainloop;
|
||||
}
|
||||
try {
|
||||
bs.saveKonten();
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
//
|
||||
System.out.println("Auf Wiedersehen!");
|
||||
|
||||
} // hauptmenü
|
||||
}
|
||||
|
||||
private void kontenLaden() throws Exception {
|
||||
bs.loadKonten();
|
||||
|
||||
}
|
||||
|
||||
private void kontoauszügeAnsugeben() {
|
||||
System.out.println("Geben Sie ihre Kontonummer ein");
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package persistence;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
|
||||
public class Persistenc {
|
||||
|
||||
|
||||
public void saveKontos(Bank bank) throws Exception {
|
||||
// File fileKonton = new File("Konten.txt");
|
||||
FileOutputStream fOS;
|
||||
fOS = new FileOutputStream("Konten.ser");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(fOS);
|
||||
oos.writeObject(bank);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
fOS.close();
|
||||
}
|
||||
|
||||
public Bank load() throws Exception {
|
||||
// File toRead = new File("Konten.ser");
|
||||
FileInputStream fis = new FileInputStream("Konten.ser");
|
||||
ObjectInputStream ois = new ObjectInputStream(fis);
|
||||
Bank bank = (Bank) ois.readObject();
|
||||
ois.close();
|
||||
fis.close();
|
||||
return bank;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue