forked from hummel/Bank-System
Neu aufgesetzt
parent
d4c17f9e65
commit
6e3d1e2a55
|
@ -11,7 +11,10 @@ public class Bank implements Serializable {
|
|||
public Bank(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public Bank() {
|
||||
}
|
||||
|
||||
public void addKonto(Konto k) {
|
||||
konten.put(k.getKontonummer(), k);
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ public class Konto implements Serializable {
|
|||
private int nummer;
|
||||
private long stand = 0;
|
||||
private String inhaber;
|
||||
private ArrayList<String> kontoauszug = new ArrayList<String>();
|
||||
private ArrayList<Kontoauszug> kontoauszug = new ArrayList<>();
|
||||
|
||||
Date date = Calendar.getInstance().getTime();
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
String datum = dateFormat.format(date);
|
||||
|
||||
|
||||
|
@ -44,13 +44,8 @@ public class Konto implements Serializable {
|
|||
}
|
||||
|
||||
public void kontoauszugAdd(long wert) {
|
||||
String wertNeu = Long.toString(wert);
|
||||
if(wert >= 0) {
|
||||
wertNeu = "+" + wert;
|
||||
}
|
||||
kontoauszug.add(wertNeu);
|
||||
kontoauszug.add(datum);
|
||||
kontoauszug.add(this.inhaber); //noch umändern zum "richtigen" Auftraggeber
|
||||
Kontoauszug kNeu = new Kontoauszug(wert, datum, inhaber);
|
||||
kontoauszug.add(kNeu);
|
||||
}
|
||||
|
||||
public int kontoauszugLänge() {
|
||||
|
@ -58,7 +53,7 @@ public class Konto implements Serializable {
|
|||
}
|
||||
|
||||
public String kontoauszugInhalt(int zähler) {
|
||||
return kontoauszug.get(zähler);
|
||||
return kontoauszug.get(zähler).getKontoauszug();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Kontoauszug implements Serializable {
|
||||
|
||||
private long betrag;
|
||||
private String datum;
|
||||
private String person;
|
||||
|
||||
public Kontoauszug(long betrag, String datum, String person) {
|
||||
this.betrag = betrag;
|
||||
this.datum = datum;
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public String getKontoauszug() {
|
||||
return "Datum: " + datum + ", Person: " + person + ", Betrag: " + betrag + " Euro";
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
|||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
import de.hs_mannheim.informatik.bank.persistence.Speicherung;
|
||||
|
||||
public class Banksystem implements Serializable {
|
||||
private Bank bank;
|
||||
|
@ -87,4 +88,12 @@ public class Banksystem implements Serializable {
|
|||
}
|
||||
return kontoauszugListe;
|
||||
}
|
||||
|
||||
public void kontoSpeichern () {
|
||||
Speicherung.speichern(bank);
|
||||
}
|
||||
|
||||
public void kontoAuslesen () {
|
||||
bank = Speicherung.auslesen();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.persistence;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class ObjectStreams {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// Daten speichern
|
||||
String s = "Die Antwort auf alles.";
|
||||
Integer i = 42;
|
||||
int[] arr = {0,8, 15};
|
||||
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("object.ser"));
|
||||
|
||||
oos.writeObject(s);
|
||||
oos.writeObject(i);
|
||||
oos.writeByte(21);
|
||||
oos.writeObject(arr);
|
||||
|
||||
oos.close();
|
||||
|
||||
// ... und wieder einlesen
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("object.ser"));
|
||||
|
||||
System.out.println((String)ois.readObject());
|
||||
System.out.println((Integer)ois.readObject());
|
||||
System.out.println(ois.readByte());
|
||||
System.out.println( ((int[])ois.readObject())[1] );
|
||||
|
||||
ois.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package de.hs_mannheim.informatik.bank.persistence;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
|
||||
public class Speicherung {
|
||||
|
||||
public static void speichern (Bank bank) {
|
||||
try {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("object.ser"));
|
||||
oos.writeObject(bank);
|
||||
oos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Bank auslesen () {
|
||||
Bank bank = new Bank();
|
||||
try {
|
||||
ObjectInputStream ois = null;
|
||||
ois = new ObjectInputStream(new FileInputStream("object.ser"));
|
||||
bank = (Bank)ois.readObject();
|
||||
ois.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bank;
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ public class UI implements Serializable {
|
|||
|
||||
private void hauptmenü() {
|
||||
System.out.println("Willkommen bei der " + bs.getBankname() + "!");
|
||||
bs.kontoAuslesen();
|
||||
|
||||
mainloop:
|
||||
while (true) {
|
||||
|
@ -42,7 +43,7 @@ public class UI implements Serializable {
|
|||
case 4: geldAuszahlen(); break;
|
||||
case 5: kontostandAnzeigen(); break;
|
||||
case 6: kontoauszugAnzeigen(); break;
|
||||
case 9: break mainloop;
|
||||
case 9: bs.kontoSpeichern(); break mainloop;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,11 +138,11 @@ public class UI implements Serializable {
|
|||
System.out.println("Folgende Kontoauszüge sind aktuell verfügbar: \n");
|
||||
int j = 1;
|
||||
for(int i = 0; i < kontenauszugInhalt.length; i++) {
|
||||
System.out.print("Auszug " + j + ": " + kontenauszugInhalt[i]);
|
||||
i++;
|
||||
System.out.print(" vom " + kontenauszugInhalt[i]);
|
||||
i++;
|
||||
System.out.println(" von " + kontenauszugInhalt[i]);
|
||||
System.out.println("Auszug " + j + ": " + kontenauszugInhalt[i]);
|
||||
// i++;
|
||||
// System.out.print(" vom " + kontenauszugInhalt[i]);
|
||||
// i++;
|
||||
// System.out.println(" von " + kontenauszugInhalt[i]);
|
||||
j++;
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue