forked from hummel/Bank-System
Exception hinzugefügt
parent
51af35d41a
commit
6e5f4b24da
|
@ -4,10 +4,11 @@ import java.io.IOException;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||||
|
import exception.BankException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException, BankException {
|
||||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||||
UI ui = new UI(bs);
|
UI ui = new UI(bs);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import exception.BankException;
|
||||||
|
|
||||||
public class Konto implements Serializable{
|
public class Konto implements Serializable{
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -31,7 +33,10 @@ public class Konto implements Serializable{
|
||||||
return inhaber;
|
return inhaber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void einzahlenKonto(long betrag) {
|
public void einzahlenKonto(long betrag) throws BankException {
|
||||||
|
if (betrag < 0) {
|
||||||
|
throw new BankException("Betrag darf nicht negativ sein");
|
||||||
|
}
|
||||||
this.stand = stand + betrag;
|
this.stand = stand + betrag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
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 exception.BankException;
|
||||||
import persistence.PersistenzSerialisiert;
|
import persistence.PersistenzSerialisiert;
|
||||||
|
|
||||||
public class Banksystem {
|
public class Banksystem {
|
||||||
|
@ -42,7 +43,7 @@ public class Banksystem {
|
||||||
return bank.getKonten().get(kNummer);
|
return bank.getKonten().get(kNummer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void einzahlenBanksystem(int kNummer, long betrag) {
|
public void einzahlenBanksystem(int kNummer, long betrag) throws BankException {
|
||||||
bank.getKonten().get(kNummer).einzahlenKonto(betrag);
|
bank.getKonten().get(kNummer).einzahlenKonto(betrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,20 +4,20 @@ import java.io.IOException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||||
|
import exception.BankException;
|
||||||
import persistence.PersistenzSerialisiert;
|
import persistence.PersistenzSerialisiert;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
private Banksystem bs;
|
private Banksystem bs;
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
public UI(Banksystem bs) throws IOException, ClassNotFoundException {
|
public UI(Banksystem bs) throws IOException, ClassNotFoundException, BankException {
|
||||||
this.bs = bs;
|
this.bs = bs;
|
||||||
hauptmenü();
|
hauptmenü();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hauptmenü() throws IOException, ClassNotFoundException {
|
private void hauptmenü() throws IOException, ClassNotFoundException, BankException {
|
||||||
System.out.println("Willkommen bei der " + bs.getBankname() + "!");
|
System.out.println("Willkommen bei der " + bs.getBankname() + "!");
|
||||||
// bs.kontenLaden();
|
|
||||||
|
|
||||||
mainloop:
|
mainloop:
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -92,7 +92,7 @@ public class UI {
|
||||||
// PersistenzSerialisiert.objectSpeichern(bs.getKontoBanksystem(kontonummer));
|
// PersistenzSerialisiert.objectSpeichern(bs.getKontoBanksystem(kontonummer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void einzahlen() {
|
private void einzahlen() throws BankException {
|
||||||
System.out.println("Bitte den Namen des Kontoinhabers angeben: ");
|
System.out.println("Bitte den Namen des Kontoinhabers angeben: ");
|
||||||
String kName = sc.nextLine();
|
String kName = sc.nextLine();
|
||||||
String [] konten = bs.getKontenliste();
|
String [] konten = bs.getKontenliste();
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package exception;
|
||||||
|
|
||||||
|
public class BankException extends Exception{
|
||||||
|
|
||||||
|
public BankException(String message) {
|
||||||
|
super(message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue