Compare commits
4 Commits
Author | SHA1 | Date |
---|---|---|
mehtapilhan | c837548779 | |
mehtapilhan | d4e200beca | |
mehtapilhan | c1da0094f2 | |
mehtapilhan | 96c61e8a12 |
|
@ -1 +0,0 @@
|
|||
/.DS_Store
|
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -1,183 +1 @@
|
|||
# ---> Eclipse
|
||||
.metadata
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
.recommenders
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# PyDev specific (Python IDE for Eclipse)
|
||||
*.pydevproject
|
||||
|
||||
# CDT-specific (C/C++ Development Tooling)
|
||||
.cproject
|
||||
|
||||
# CDT- autotools
|
||||
.autotools
|
||||
|
||||
# Java annotation processor (APT)
|
||||
.factorypath
|
||||
|
||||
# PDT-specific (PHP Development Tools)
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# Tern plugin
|
||||
.tern-project
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
# STS (Spring Tool Suite)
|
||||
.springBeans
|
||||
|
||||
# Code Recommenders
|
||||
.recommenders/
|
||||
|
||||
# Annotation Processing
|
||||
.apt_generated/
|
||||
.apt_generated_test/
|
||||
|
||||
# Scala IDE specific (Scala & Java development for Eclipse)
|
||||
.cache-main
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
|
||||
# Uncomment this line if you wish to ignore the project description file.
|
||||
# Typically, this file would be tracked if it contains build/dependency configurations:
|
||||
#.project
|
||||
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# AWS User-specific
|
||||
.idea/**/aws.xml
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# SonarLint plugin
|
||||
.idea/sonarlint/
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# ---> Java
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
replay_pid*
|
||||
|
||||
# ---> VisualStudioCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
!.vscode/*.code-snippets
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
# Built Visual Studio Code Extensions
|
||||
*.vsix
|
||||
|
||||
*.ser
|
||||
/.DS_Store
|
||||
/bin/
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Bank-Beispiel</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,13 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
import de.hs_mannheim.informatik.bank.ui.UI;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
UI ui = new UI(bs);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Bank implements Serializable {
|
||||
private String name;
|
||||
private HashMap<Integer, Konto> konten = new HashMap<>();
|
||||
private int kontozähler;
|
||||
|
||||
public Bank(String name) {
|
||||
this.name = name;
|
||||
this.kontozähler = -1;
|
||||
}
|
||||
|
||||
public int addKonto(String name, int auswahl) {
|
||||
Konto k;
|
||||
|
||||
if (auswahl == 1)
|
||||
k = new Konto(name, ++kontozähler);
|
||||
else
|
||||
k = new Girokonto(name, ++kontozähler);
|
||||
|
||||
konten.put(k.getKontonummer(), k);
|
||||
|
||||
return k.getKontonummer();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Collection<Konto> getKontenliste() {
|
||||
return konten.values();
|
||||
}
|
||||
|
||||
public Konto findeKonto(int kontonummer) {
|
||||
return konten.get(kontonummer);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Girokonto extends Konto implements Serializable {
|
||||
private long dispo = 100000;
|
||||
|
||||
public Girokonto(String inhaber, int kontozähler) {
|
||||
super(inhaber, kontozähler);
|
||||
}
|
||||
|
||||
public boolean überweise(Girokonto ziel, long betrag, String zweck) {
|
||||
if (super.getKontostand() - betrag >= dispo * (-1)) {
|
||||
this.auszahlen(betrag, zweck, "Überweisungsausgang", super.getInhaber());
|
||||
ziel.einzahlen(betrag, zweck, "Überweisungseingang", super.getInhaber());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean auszahlen(long betrag, String zweck, String art, String auftraggeber) {
|
||||
if (stand - betrag >= dispo * (-1)) {
|
||||
stand -= betrag;
|
||||
|
||||
kontobewegungen.add(new Kontobewegung(betrag * -1, zweck, art, auftraggeber));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Giro-" + super.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class GirokontoTest {
|
||||
|
||||
@Test
|
||||
void testÜberziehung() {
|
||||
Konto k = new Girokonto("Müller", 0);
|
||||
k.einzahlen(10000, "Test", "Einzahlung", "JUnit");
|
||||
|
||||
assertTrue(k.auszahlen(20000, "Test", "Einzahlung", "JUnit"));
|
||||
assertEquals(-10000, k.getKontostand());
|
||||
|
||||
assertTrue(k.auszahlen(40000, "Test", "Einzahlung", "JUnit"));
|
||||
assertTrue(k.auszahlen(50000, "Test", "Einzahlung", "JUnit"));
|
||||
assertEquals(-100000, k.getKontostand());
|
||||
|
||||
assertFalse(k.auszahlen(40000, "Test", "Einzahlung", "JUnit"));
|
||||
assertFalse(k.auszahlen(1, "Test", "Einzahlung", "JUnit"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Konto implements Serializable {
|
||||
private int nummer;
|
||||
protected long stand = 0;
|
||||
private String inhaber;
|
||||
|
||||
protected ArrayList<Kontobewegung> kontobewegungen;
|
||||
|
||||
public Konto(String inhaber, int kontozähler) {
|
||||
nummer = 1000 + kontozähler;
|
||||
this.inhaber = inhaber;
|
||||
|
||||
this.kontobewegungen = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int getKontonummer() {
|
||||
return nummer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]";
|
||||
}
|
||||
|
||||
public String getInhaber() {
|
||||
return inhaber;
|
||||
}
|
||||
|
||||
public long getKontostand() {
|
||||
return stand;
|
||||
}
|
||||
|
||||
public void einzahlen(long betrag, String zweck, String art, String auftraggeber) {
|
||||
stand += betrag;
|
||||
|
||||
kontobewegungen.add(new Kontobewegung(betrag, zweck, art, auftraggeber));
|
||||
}
|
||||
|
||||
public boolean auszahlen(long betrag, String zweck, String art, String auftraggeber) {
|
||||
if (stand - betrag >= 0) {
|
||||
stand -= betrag;
|
||||
|
||||
kontobewegungen.add(new Kontobewegung(betrag * -1, zweck, art, auftraggeber));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String[] getKontobewegungen() {
|
||||
String[] auflistung = new String[kontobewegungen.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Kontobewegung kb : kontobewegungen) {
|
||||
auflistung[i++] = kb.toString();
|
||||
}
|
||||
|
||||
return auflistung;
|
||||
}
|
||||
|
||||
public long berechneSaldo(int anzahl) {
|
||||
long saldo = 0;
|
||||
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
saldo += kontobewegungen.get(i).getBetrag() ;
|
||||
}
|
||||
|
||||
return saldo;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class KontoTest {
|
||||
|
||||
@Test
|
||||
void testKontoBasics() {
|
||||
Konto k = new Konto("Müller", 0);
|
||||
assertEquals("Müller", k.getInhaber());
|
||||
assertEquals(1000, k.getKontonummer());
|
||||
assertEquals(0, k.getKontostand());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testKontoEinUndAuszahlungUndSaldo() {
|
||||
Konto k = new Konto("Müller", 0);
|
||||
Konto k2 = new Konto("Mayer", 1);
|
||||
testKontoEinUndAuszahlungUndSaldo(k, k2);
|
||||
|
||||
k = new Girokonto("Müller", 0);
|
||||
k2 = new Girokonto("Mayer", 1);
|
||||
testKontoEinUndAuszahlungUndSaldo(k, k2);
|
||||
}
|
||||
|
||||
private void testKontoEinUndAuszahlungUndSaldo(Konto k, Konto k2) {
|
||||
assertEquals("Mayer", k2.getInhaber());
|
||||
assertNotEquals(k.getKontonummer(), k2.getKontonummer());
|
||||
|
||||
k2.einzahlen(100, "Test", "Einzahlung", "JUnit");
|
||||
assertEquals(100, k2.getKontostand());
|
||||
|
||||
assertTrue(k2.auszahlen(50, "Test", "Auszahlung", "JUnit"));
|
||||
assertEquals(50, k2.getKontostand());
|
||||
|
||||
assertTrue(k2.auszahlen(50, "Test", "Auszahlung", "JUnit"));
|
||||
assertEquals(0, k2.getKontostand());
|
||||
|
||||
k2.einzahlen(100, "Test", "Einzahlung", "JUnit");
|
||||
k2.einzahlen(100, "Test", "Einzahlung", "JUnit");
|
||||
k2.einzahlen(1, "Test", "Einzahlung", "JUnit");
|
||||
|
||||
assertEquals(100, k2.berechneSaldo(1));
|
||||
assertEquals(100, k2.berechneSaldo(4));
|
||||
assertEquals(k2.getKontostand(), k2.berechneSaldo(6));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testKeineÜberziehungFürSparkonten() {
|
||||
Konto k = new Konto("Müller", 0);
|
||||
k.einzahlen(100, "Test", "Einzahlung", "JUnit");
|
||||
assertFalse(k.auszahlen(500, "Test", "Auszahlung", "JUnit"));
|
||||
|
||||
k.auszahlen(50, "Test", "Auszahlung", "JUnit");
|
||||
assertFalse(k.auszahlen(100, "Test", "Auszahlung", "JUnit"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class Kontobewegung implements Serializable {
|
||||
private long betrag;
|
||||
private Date datum;
|
||||
private String betreff;
|
||||
private String art;
|
||||
private String auftraggeber;
|
||||
|
||||
public Kontobewegung(long betrag, String betreff, String art, String auftraggeber) {
|
||||
this.betrag = betrag;
|
||||
this.betreff = betreff;
|
||||
this.art = art;
|
||||
this.auftraggeber = auftraggeber;
|
||||
|
||||
this.datum = new Date();
|
||||
}
|
||||
|
||||
public long getBetrag() {
|
||||
return betrag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Kontobewegung [betrag=" + betrag + ", datum=" + datum + ", betreff=" + betreff + ", art=" + art
|
||||
+ ", auftraggeber=" + auftraggeber + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Girokonto;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
import de.hs_mannheim.informatik.bank.infrastructure.Persistenz;
|
||||
|
||||
public class Banksystem {
|
||||
private Bank bank;
|
||||
|
||||
public Banksystem(String bankname) throws Exception {
|
||||
if (Persistenz.sindDatenGespeichert(bankname))
|
||||
this.bank = (Bank) Persistenz.ladeBankDaten(bankname);
|
||||
else
|
||||
this.bank = new Bank(bankname);
|
||||
}
|
||||
|
||||
public int kontoAnlegen(String name, int auswahl) throws Exception {
|
||||
int kontonummer = bank.addKonto(name, auswahl);
|
||||
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
return kontonummer;
|
||||
}
|
||||
|
||||
public String[] getKontenliste() {
|
||||
Collection<Konto> konten = bank.getKontenliste();
|
||||
String[] liste = new String[konten.size()];
|
||||
|
||||
int i = 0;
|
||||
for (Konto k : konten) {
|
||||
liste[i++] = k.toString();
|
||||
}
|
||||
|
||||
return liste;
|
||||
}
|
||||
|
||||
public String getBankname() {
|
||||
return bank.getName();
|
||||
}
|
||||
|
||||
public long geldEinzahlen(int kontonummer, long betrag) throws Exception {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
konto.einzahlen(betrag, "Einzahlung am Schalter", "Einzahlung", konto.getInhaber());
|
||||
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
return konto.getKontostand();
|
||||
}
|
||||
|
||||
public boolean geldAuszahlen(int kontonummer, long betrag) throws Exception {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
|
||||
boolean erg = konto.auszahlen(betrag, "Auszahlung am Schalter", "Auszahlung", konto.getInhaber());
|
||||
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
return erg;
|
||||
}
|
||||
|
||||
public String[] erstelleKontoauszug(int kontonummer) {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
|
||||
return konto.getKontobewegungen();
|
||||
}
|
||||
|
||||
public boolean überweisungBeauftragen(int startkonto, int zielkonto, long betrag, String verwendungszweck) throws Exception {
|
||||
Konto start = bank.findeKonto(startkonto);
|
||||
Konto ziel = bank.findeKonto(zielkonto);
|
||||
|
||||
if (start instanceof Girokonto && ziel instanceof Girokonto) {
|
||||
boolean erfolg = ((Girokonto)start).überweise((Girokonto)ziel, betrag, verwendungszweck);
|
||||
Persistenz.speichereBankDaten(this.bank, bank.getName());
|
||||
|
||||
return erfolg;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getKontostand(int kontonummer) {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
|
||||
return konto.getKontostand();
|
||||
}
|
||||
|
||||
public long saldoBestimmen(int kontonummer, int anzahl) {
|
||||
Konto konto = bank.findeKonto(kontonummer);
|
||||
|
||||
return konto.berechneSaldo(anzahl);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class SystemTest {
|
||||
private static Banksystem bs;
|
||||
|
||||
@BeforeAll
|
||||
static void initBanksystem() throws Exception {
|
||||
bs = new Banksystem("Testsystem");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void smokeTest() {
|
||||
assertNotNull(bs);
|
||||
assertEquals(0, bs.getKontenliste().length);
|
||||
assertEquals("Testsystem", bs.getBankname());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void einzahlenTest() throws Exception {
|
||||
int knr = bs.kontoAnlegen("Test1", 1);
|
||||
|
||||
assertEquals(1000, bs.geldEinzahlen(knr, 1000));
|
||||
|
||||
bs.geldEinzahlen(knr, 1);
|
||||
assertEquals(1001, bs.getKontostand(knr));
|
||||
|
||||
assertEquals(1001, bs.geldEinzahlen(knr, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void persistenzTest() throws Exception {
|
||||
int knr = bs.kontoAnlegen("Test2", 2);
|
||||
int knr2 = bs.kontoAnlegen("Test3", 2);
|
||||
|
||||
bs.geldEinzahlen(knr, 1000);
|
||||
bs.geldAuszahlen(knr, 500);
|
||||
assertTrue(bs.überweisungBeauftragen(knr, knr2, 100, "Überweisungstest."));
|
||||
|
||||
assertEquals(400, bs.getKontostand(knr));
|
||||
|
||||
bs = null;
|
||||
|
||||
Banksystem bs2 = new Banksystem("Testsystem");
|
||||
assertEquals(400, bs2.getKontostand(knr));
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void cleanup() {
|
||||
File file = new File("/Users/oliver/git/Bank-System/Bank-Beispiel/Testsystem-bank-data.ser");
|
||||
file.delete();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.infrastructure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
public class Persistenz {
|
||||
private static final String BANK_DATEI = "-bank-data.ser";
|
||||
|
||||
public static boolean sindDatenGespeichert(String name) {
|
||||
return new File(name + BANK_DATEI).exists();
|
||||
}
|
||||
|
||||
public static void speichereBankDaten(Object bank, String name) throws Exception {
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(name + BANK_DATEI));
|
||||
oos.writeObject(bank);
|
||||
oos.close();
|
||||
}
|
||||
|
||||
public static Object ladeBankDaten(String name) throws Exception {
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(name + BANK_DATEI));
|
||||
Object bank = ois.readObject();
|
||||
ois.close();
|
||||
|
||||
return bank;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.ui;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.facade.Banksystem;
|
||||
|
||||
public class UI {
|
||||
private Banksystem bs;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
public UI(Banksystem bs) {
|
||||
this.bs = bs;
|
||||
hauptmenü();
|
||||
}
|
||||
|
||||
private void hauptmenü() {
|
||||
System.out.println("Willkommen bei der " + bs.getBankname() + "!");
|
||||
|
||||
mainloop:
|
||||
while (true) {
|
||||
System.out.println();
|
||||
System.out.println("--------");
|
||||
System.out.println("Hauptmenü");
|
||||
System.out.println("1 -> Konten anzeigen");
|
||||
System.out.println("2 -> Konto anlegen");
|
||||
System.out.println("3 -> Geld einzahlen");
|
||||
System.out.println("4 -> Geld auszahlen");
|
||||
System.out.println("5 -> Kontoauszug drucken");
|
||||
System.out.println("6 -> Überweisung beauftragen");
|
||||
System.out.println("7 -> Saldo abfragen");
|
||||
|
||||
System.out.println("9 -> Beenden");
|
||||
System.out.println();
|
||||
|
||||
System.out.print("> ");
|
||||
int input = Integer.parseInt(sc.nextLine());
|
||||
System.out.println();
|
||||
|
||||
try {
|
||||
switch(input) {
|
||||
case 1: kontenAnzeigen(); break;
|
||||
case 2:
|
||||
kontoAnlegen();
|
||||
break;
|
||||
case 3: geldEinzahlen(); break;
|
||||
case 4: geldAuszahlen(); break;
|
||||
case 5: kontoauszugDrucken(); break;
|
||||
case 6: überweisungBeauftragen(); break;
|
||||
case 7: saldoAbfragen(); break;
|
||||
case 9: break mainloop;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getLocalizedMessage());
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
System.out.println("Auf Wiedersehen!");
|
||||
|
||||
} // hauptmenü
|
||||
|
||||
private void kontenAnzeigen() {
|
||||
String[] konten = bs.getKontenliste();
|
||||
if (konten.length > 0) {
|
||||
System.out.println("Folgende Konten sind aktuell verfügbar:");
|
||||
for (String s : konten) {
|
||||
System.out.println(s);
|
||||
}
|
||||
} else {
|
||||
System.out.println("Bisher keine Konten angelegt.");
|
||||
}
|
||||
}
|
||||
|
||||
private void kontoAnlegen() throws Exception {
|
||||
System.out.println("Bitte den Namen des Kontoinhabers angeben: ");
|
||||
String name = sc.nextLine();
|
||||
|
||||
System.out.println("Möchten Sie ein Sparkonto (1) oder ein Girokonto (2) anlegen?");
|
||||
int auswahl = Integer.parseInt(sc.nextLine());
|
||||
|
||||
int kontonummer = bs.kontoAnlegen(name, auswahl);
|
||||
System.out.println("Konto mit der Nummer " + kontonummer + " neu angelegt.");
|
||||
}
|
||||
|
||||
private void geldEinzahlen() throws Exception {
|
||||
System.out.println("Geld einzahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
||||
|
||||
// optional prüfen, ob Konto existiert
|
||||
|
||||
System.out.print("Bitte den gewünschten Betrag eingeben: ");
|
||||
double betrag = Double.parseDouble(sc.nextLine());
|
||||
|
||||
long neuerKontostand = bs.geldEinzahlen(kontonummer, (long)betrag * 100);
|
||||
|
||||
System.out.printf("Einzahlung erfolgreich, neuer Kontostand = %.2f Euro", (neuerKontostand / 100.0));
|
||||
}
|
||||
|
||||
private void geldAuszahlen() throws Exception {
|
||||
System.out.println("Geld auszahlen");
|
||||
System.out.print("Bitte die gewünschte Kontonummer eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
||||
|
||||
System.out.print("Bitte den gewünschten Betrag eingeben: ");
|
||||
double betrag = Double.parseDouble(sc.nextLine());
|
||||
|
||||
boolean erfolgreich = bs.geldAuszahlen(kontonummer, (long)betrag * 100);
|
||||
|
||||
System.out.printf("Auszahlung" + ((!erfolgreich)? " nicht" : "" )+ " erfolgreich. ");
|
||||
System.out.printf("Neuer Kontostand = %.2f Euro.", (bs.getKontostand(kontonummer) / 100.0));
|
||||
}
|
||||
|
||||
private void kontoauszugDrucken() {
|
||||
System.out.print("Bitte die gewünschte Kontonummer für den Auszug eingeben: ");
|
||||
int kontonummer = Integer.parseInt(sc.nextLine());
|
||||
|
||||
// in echt auf einem Drucker
|
||||
System.out.println("Auszug für Konto " + kontonummer);
|
||||
String[] kontobewegungen = bs.erstelleKontoauszug(kontonummer);
|
||||
|
||||
if (kontobewegungen.length > 0)
|
||||
for (String kb : kontobewegungen) {
|
||||
System.out.println(kb);
|
||||
}
|
||||
else
|
||||
System.out.println("Noch keine Kontobewegungen.");
|
||||
}
|
||||
|
||||
private void überweisungBeauftragen() throws Exception {
|
||||
System.out.print("Bitte die Kontonummer des Ausgangskontos der Überweisung eingeben: ");
|
||||
int startkonto = Integer.parseInt(sc.nextLine());
|
||||
|
||||
System.out.print("Bitte die Kontonummmer für das Zielkonto der Überweisung eingeben: ");
|
||||
int zielkonto = Integer.parseInt(sc.nextLine());
|
||||
|
||||
System.out.print("Bitte den gewünschten Überweisungsbetrag eingeben: ");
|
||||
double betrag = Double.parseDouble(sc.nextLine());
|
||||
|
||||
System.out.print("Bitte den Verwendungszweck eingeben: ");
|
||||
String verwendungszweck = sc.nextLine();
|
||||
|
||||
boolean erfolgreich = bs.überweisungBeauftragen(startkonto, zielkonto, (long)(betrag * 100), verwendungszweck);
|
||||
|
||||
System.out.println("Überweisung" + ( (!erfolgreich) ? " nicht" : "") + " erfolgreich ausgeführt.");
|
||||
}
|
||||
|
||||
private void saldoAbfragen() {
|
||||
System.out.print("Bitte die Kontonummer des gewünschten Kontos eingeben: ");
|
||||
int konto = Integer.parseInt(sc.nextLine());
|
||||
|
||||
System.out.print("Bitte die Anzahl der Kontobewegungen für den Saldo eingeben: ");
|
||||
int anzahl = Integer.parseInt(sc.nextLine());
|
||||
|
||||
long saldo = bs.saldoBestimmen(konto, anzahl);
|
||||
System.out.printf("Der Saldo nach %d Kontobewegungen beträgt %.2f Euro.%n", anzahl, (saldo/100d));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue