master
ahmad 2022-10-11 14:12:42 +02:00
parent d2e9e7e855
commit 050e8363ad
7 changed files with 144 additions and 4 deletions

View File

@ -3,10 +3,12 @@ package de.hs_mannheim.informatik.bank;
import de.hs_mannheim.informatik.bank.UI.UI; import de.hs_mannheim.informatik.bank.UI.UI;
import de.hs_mannheim.informatik.bank.facade.Banksystem; import de.hs_mannheim.informatik.bank.facade.Banksystem;
import persistance.Read;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
Read r = new Read();
Banksystem bs = new Banksystem("Spaßkasse Mannheim"); Banksystem bs = new Banksystem("Spaßkasse Mannheim");
UI ui = new UI(bs); UI ui = new UI(bs);
} }

View File

@ -17,7 +17,7 @@ public class UI {
hauptmenu(); hauptmenu();
} }
private void hauptmenu() { private void hauptmenu() {
System.out.println("Willkommen bei der " + bs.getBankname() + "!"); System.out.println("Willkommen bei der " + bs.getBankname() + "!");
mainloop: mainloop:
@ -31,6 +31,8 @@ public class UI {
System.out.println("4 -> Auszahlen"); System.out.println("4 -> Auszahlen");
System.out.println("5 -> Kontostand Suchen"); System.out.println("5 -> Kontostand Suchen");
System.out.println("6 -> Verlauf Zeigen"); System.out.println("6 -> Verlauf Zeigen");
System.out.println("7 -> Speichern");
System.out.println("8 -> laden");
System.out.println("9 -> Beenden"); System.out.println("9 -> Beenden");
System.out.println(); System.out.println();
@ -43,8 +45,13 @@ public class UI {
case 2: kontoAnlegen(); break; case 2: kontoAnlegen(); break;
case 3: einzahlen(); break; case 3: einzahlen(); break;
case 4: ausziehen(); break; case 4: ausziehen(); break;
case 5: standSuchen(); break; case 5: standSuchen(); break;
case 6: zeigeVerlauf(); break; case 6: zeigeVerlauf(); break;
case 7: speichern(); break;
case 8: laden(); break;
case 9: break mainloop; case 9: break mainloop;
} }
@ -128,5 +135,32 @@ public class UI {
} }
private void speichern()
{
if(bs.speichern())
{
System.out.println("Date gespeichert");
return;
}else
{
System.out.println("Ein Fehler ist aufgetreten");
}
}
private void laden()
{
try {
if(bs.laden())
{
System.out.println("Data gespeichert");
return;
}
}
catch(ClassNotFoundException a)
{
System.out.println("Ein Fehler ist aufgetreten");
}
}
} }

View File

@ -5,10 +5,23 @@ package de.hs_mannheim.informatik.bank.domain;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import persistance.Read;
import persistance.Write;
public class Bank { public class Bank {
private String name; private String name;
private HashMap<Integer, Konto> konten = new HashMap<>(); private HashMap<Integer, Konto> konten = new HashMap<>();
public HashMap<Integer, Konto> getKonten() {
return konten;
}
public void setKonten(HashMap<Integer, Konto> konten) {
this.konten = konten;
}
public Bank(String name) { public Bank(String name) {
this.name = name; this.name = name;
} }
@ -25,6 +38,13 @@ public class Bank {
return konten.values(); return konten.values();
} }
public boolean save()
{
Write w = new Write();
return w.saveFile(konten);
}
} }

View File

@ -1,9 +1,10 @@
package de.hs_mannheim.informatik.bank.domain; package de.hs_mannheim.informatik.bank.domain;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Konto { public class Konto implements Serializable{
private static int kontozähler = 0; private static int kontozähler = 0;
private List<Long> history = new ArrayList<Long>(); private List<Long> history = new ArrayList<Long>();

View File

@ -2,12 +2,15 @@ package de.hs_mannheim.informatik.bank.facade;
import java.util.ArrayList; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap;
import java.util.List; import java.util.List;
import de.hs_mannheim.informatik.bank.domain.Bank; import de.hs_mannheim.informatik.bank.domain.Bank;
import de.hs_mannheim.informatik.bank.domain.Konto; import de.hs_mannheim.informatik.bank.domain.Konto;
import persistance.Read;
import persistance.Write;
public class Banksystem { public class Banksystem {
private Bank bank; private Bank bank;
@ -100,5 +103,21 @@ public class Banksystem {
return null; return null;
} }
public boolean laden() throws ClassNotFoundException
{
Read r = new Read();
HashMap<Integer,Konto> x = r.load();
if(x == null) return false;
bank.setKonten(r.load());
return true;
}
public boolean speichern()
{
Write w = new Write();
return w.saveFile(bank.getKonten());
}
} }

View File

@ -0,0 +1,29 @@
package persistance;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.HashMap;
import de.hs_mannheim.informatik.bank.domain.Konto;
public class Read {
public HashMap<Integer,Konto> load() throws ClassNotFoundException
{
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("object.ser"));
HashMap<Integer, Konto> map = (HashMap<Integer, Konto>) ois.readObject();
ois.close();
return map;
} catch(IOException e )
{
return null;
}
}
}

View File

@ -0,0 +1,35 @@
package persistance;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import de.hs_mannheim.informatik.bank.domain.Konto;
public class Write {
public boolean saveFile(HashMap<Integer, Konto> data)
{
try{
FileOutputStream fos =new FileOutputStream("object.ser");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(data);
fos.close();
oos.close();
return true;
}
catch(IOException a)
{
System.out.println("tff");
return false;
}
}
}