forked from hummel/Bank-System
unbennenung
parent
d4e200beca
commit
c837548779
11
.project
11
.project
|
@ -1,11 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Bank-SystemMeins</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -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,181 +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
|
||||
|
||||
/bin/
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Bank-BeispielMeins</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>
|
Binary file not shown.
|
@ -1,14 +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) {
|
||||
Banksystem bs = new Banksystem("Spaßkasse Mannheim");
|
||||
|
||||
UI ui = new UI(bs);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class Bank implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4051540516262811680L;
|
||||
private String name;
|
||||
private HashMap<Integer, Konto> konten = new HashMap<>();
|
||||
|
||||
public Bank(String name) { // bank kriegt name
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void addKonto(Konto k) { // ein konto wird hinzugefügt mit der neuen kontonummer
|
||||
konten.put(k.getKontonummer(), k);
|
||||
}
|
||||
|
||||
public long zahleEin(Integer kontonummer, long einzahlung) { // object konto wird erstellt mit dem kontonummer und wird auf den minimalwert geprüft und einzahlen aufgerufen
|
||||
Konto konto = konten.get(kontonummer);
|
||||
|
||||
if(konto == null)
|
||||
return Long.MIN_VALUE;
|
||||
|
||||
return konto.zahleEin(einzahlung);
|
||||
}
|
||||
|
||||
public String getName() { // getter für Name und Kontostand wird errichtet
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getKontostand(Integer kontonummer) {
|
||||
Konto konto = konten.get(kontonummer);
|
||||
|
||||
if(konto == null)
|
||||
return Long.MIN_VALUE;
|
||||
|
||||
return konto.getKontostand();
|
||||
}
|
||||
|
||||
// Damit nicht auf nicht existierende Konten eingezahlt werden kann
|
||||
public boolean existiertKonto(Integer kontonummer) {
|
||||
return konten.containsKey(kontonummer);
|
||||
}
|
||||
|
||||
public Collection<Konto> getKontenliste() { //kontenliste wird
|
||||
return konten.values();
|
||||
}
|
||||
|
||||
public List<Kontoauszug> getAuszuge(Integer kontonummer) { //arrayliste mit kontoauszug wird erstellt
|
||||
Konto konto = konten.get(kontonummer);
|
||||
|
||||
if(konto == null)
|
||||
return new ArrayList<>();
|
||||
|
||||
return konto.getAuszuge();
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Konto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1281848917479629785L;
|
||||
|
||||
private static int kontozähler = 0; // warum nicht hier direkt auf 1000 setzen
|
||||
|
||||
private int nummer;
|
||||
private long stand = 0;
|
||||
private String inhaber;
|
||||
|
||||
private ArrayList<Kontoauszug> auszuge = new ArrayList<>();
|
||||
|
||||
public Konto(String inhaber) {
|
||||
nummer = 1000 + kontozähler++; // warum ab 1000?
|
||||
this.inhaber = inhaber;
|
||||
}
|
||||
|
||||
|
||||
public int getKontonummer() {
|
||||
return nummer;
|
||||
}
|
||||
|
||||
public long getKontostand() {
|
||||
return stand;
|
||||
}
|
||||
|
||||
|
||||
public long zahleEin(long einzahlung) {
|
||||
this.stand += einzahlung;
|
||||
// inhaber muss theoretisch ermittelt werden mit scanner
|
||||
auszuge.add(new Kontoauszug(stand, einzahlung, inhaber));
|
||||
return stand;
|
||||
}
|
||||
|
||||
public List<Kontoauszug> getAuszuge() {
|
||||
return auszuge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]"; // warum fehlt der kontostand
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class KontoTest {
|
||||
//assertEquals testet ob zahleEin() den Kontostand richtig erhöht
|
||||
@Test
|
||||
void testzahleEin(){
|
||||
Konto konto = new Konto ("Hans");
|
||||
long zahl1 = 5000;
|
||||
konto.zahleEin(zahl1);
|
||||
assertEquals(konto.getKontostand(), zahl1);
|
||||
|
||||
}
|
||||
@Test
|
||||
void testzahleEin2() {
|
||||
Konto konto = new Konto ("Hans");
|
||||
long zahl1 = -500;
|
||||
konto.zahleEin(zahl1);
|
||||
assertNotEquals(konto.getKontostand(), 5);
|
||||
}
|
||||
//es gibt keine methode für zahleaus, wir testen zahleEin auf negativem betrag
|
||||
@Test
|
||||
void testzahleAus() {
|
||||
Konto konto = new Konto ("Hans");
|
||||
long zahl1 = -100;
|
||||
konto.zahleEin(zahl1);
|
||||
assertEquals(konto.getKontostand(), zahl1);
|
||||
}
|
||||
|
||||
//test ob die erste Kontonummer richtig vergeben wird
|
||||
@Test
|
||||
void testKontonummer() {
|
||||
Konto konto = new Konto ("bauer");
|
||||
assertEquals(konto.getKontonummer(), 1003);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
public class Kontoauszug implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1220632421439291641L;
|
||||
private long kontostand, betrag;
|
||||
private Date date = new Date();
|
||||
private String auftraggeber;
|
||||
|
||||
public Kontoauszug(long kontostand, long betrag, String auftraggeber) {
|
||||
this.kontostand = kontostand;
|
||||
this.betrag = betrag;
|
||||
this.auftraggeber = auftraggeber;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Datum: " + date.toString() + " | Kontostand: " + kontostand + " | Betrag: " + (betrag < 0 ? "-" : "+") + betrag + " | " + "Auftraggeber: " + auftraggeber;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
import de.hs_mannheim.informatik.bank.domain.Kontoauszug;
|
||||
import persistence.BankSerializer;
|
||||
|
||||
public class Banksystem {
|
||||
private Bank bank;
|
||||
|
||||
public Banksystem(String bankname) {
|
||||
this.bank = new Bank(bankname);
|
||||
}
|
||||
|
||||
|
||||
public int kontoAnlegen(String name) {
|
||||
Konto k = new Konto(name);
|
||||
bank.addKonto(k);
|
||||
|
||||
return k.getKontonummer();
|
||||
}
|
||||
|
||||
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 long zahleEin(Integer kontonummer, long einzahlung) {
|
||||
return bank.zahleEin(kontonummer, einzahlung);
|
||||
}
|
||||
|
||||
public long getKontostand(Integer kontonummer) {
|
||||
return bank.getKontostand(kontonummer);
|
||||
}
|
||||
|
||||
// Damit nicht auf nicht existierende Konten eingezahlt werden kann
|
||||
public boolean existiertKonto(Integer kontonummer) {
|
||||
return bank.existiertKonto(kontonummer);
|
||||
}
|
||||
|
||||
public String getBankname() {
|
||||
return bank.getName();
|
||||
}
|
||||
|
||||
|
||||
public List<Kontoauszug> getAuszuge(Integer kontonummer) {
|
||||
return bank.getAuszuge(kontonummer);
|
||||
}
|
||||
//Erklärung Serializer, null hat keinen Wert und Bank wird mit this aufgerufen wegen private
|
||||
public void ladeSitzung() {
|
||||
Bank bank = BankSerializer.readFromFile("meine_tolle_bank.txt");
|
||||
if(bank != null)
|
||||
this.bank = bank;
|
||||
}
|
||||
|
||||
public void speichereSitzung() {
|
||||
BankSerializer.saveToFile("meine_tolle_bank.txt", bank);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.facade;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
import de.hs_mannheim.informatik.bank.domain.Konto;
|
||||
|
||||
class BanksystemTest {
|
||||
|
||||
@Test
|
||||
void testkontoAnlegen() {
|
||||
Banksystem bs = new Banksystem ("Sparkasse");
|
||||
String name = "Peter";
|
||||
|
||||
assertEquals(bs.kontoAnlegen(name) ,1000 );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
package de.hs_mannheim.informatik.bank.ui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import de.hs_mannheim.informatik.bank.domain.Kontoauszug;
|
||||
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;
|
||||
bs.speichereSitzung();
|
||||
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 -> Auf Konto einzahlen");
|
||||
System.out.println("4 -> Von Konto abheben");
|
||||
System.out.println("5 -> Kontostand anzeigen");
|
||||
System.out.println("6 -> Kontoauszug anzeigen");
|
||||
System.out.println("9 -> Beenden");
|
||||
System.out.println();
|
||||
|
||||
System.out.print("> ");
|
||||
String input = sc.nextLine();
|
||||
int inputNumber = 0;
|
||||
|
||||
if(!input.equalsIgnoreCase(""))
|
||||
inputNumber = Integer.parseInt(input);
|
||||
|
||||
System.out.println();
|
||||
|
||||
switch(inputNumber) {
|
||||
case 1: kontenAnzeigen(); break;
|
||||
case 2: kontoAnlegen(); break;
|
||||
case 3: kontoEinzahlen(); break;
|
||||
case 4: kontoAbheben(); break;
|
||||
case 5: kontostandAnzeigen(); break;
|
||||
case 6: kontoauszugAnzeigen(); break;
|
||||
case 9: bs.speichereSitzung(); break mainloop;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
System.out.println("Bitte den Namen des Kontoinhabers angeben: ");
|
||||
String name = sc.nextLine(); // warum kein null check / empty check
|
||||
|
||||
int kontonummer = bs.kontoAnlegen(name);
|
||||
System.out.print("Konto mit der Nummer " + kontonummer + " neu angelegt.");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
private void kontoEinzahlen() {
|
||||
// Konto ermitteln
|
||||
System.out.print("Bitte die Kontonummer angeben: ");
|
||||
Integer kontonummer = sc.nextInt(); // warum kein null check / empty check
|
||||
|
||||
|
||||
if(!bs.existiertKonto(kontonummer)) {
|
||||
System.out.print("Kein Konto mit dieser Kontonummer existiert.");
|
||||
return;
|
||||
// hier kann man auch wieder kontoEinzahlen aufrufen, für eine erneute Eingabemöglichkeit, dann muss aber vorher geprüft werden, ob Konten existieren.
|
||||
}
|
||||
|
||||
// Betrag ermitteln
|
||||
System.out.print("Bitte den einzuzahlenden Betrag angeben: ");
|
||||
long betrag = sc.nextLong();
|
||||
|
||||
|
||||
// Einzahlen
|
||||
long kontostand = bs.zahleEin(kontonummer, betrag);
|
||||
System.out.print("Konto mit der Nummer " + kontonummer + " hat einen Kontostand von " + kontostand);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
private void kontoAbheben() {
|
||||
// Konto ermitteln
|
||||
System.out.println("Bitte die Kontonummer angeben: ");
|
||||
Integer kontonummer = sc.nextInt();
|
||||
|
||||
if(!bs.existiertKonto(kontonummer)) {
|
||||
System.out.println("Kein Konto mit dieser Kontonummer existiert.");
|
||||
kontoAbheben();
|
||||
return;// könnte auch return rein
|
||||
}
|
||||
|
||||
// Betrag ermitteln
|
||||
System.out.println("Bitte den abzuhebenden Betrag angeben: ");
|
||||
long betrag = sc.nextLong();
|
||||
|
||||
// Abheben
|
||||
long kontostand = bs.zahleEin(kontonummer, -betrag);
|
||||
System.out.println("Konto mit der Nummer " + kontonummer + " hat einen Kontostand von " + kontostand);
|
||||
}
|
||||
|
||||
private void kontoauszugAnzeigen() {
|
||||
// Konto ermitteln
|
||||
System.out.println("Bitte die Kontonummer angeben: ");
|
||||
Integer kontonummer = sc.nextInt();
|
||||
|
||||
if(!bs.existiertKonto(kontonummer)) {
|
||||
System.out.println("Kein Konto mit dieser Kontonummer existiert.");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
List<Kontoauszug> auszuge = bs.getAuszuge(kontonummer);
|
||||
|
||||
for(Kontoauszug auszug : auszuge)
|
||||
System.out.println(auszug);
|
||||
}
|
||||
|
||||
private void kontostandAnzeigen() {
|
||||
// Konto ermitteln
|
||||
System.out.println("Bitte die Kontonummer angeben: ");
|
||||
Integer kontonummer = sc.nextInt();
|
||||
|
||||
System.out.println("Konto mit der Nummer " + kontonummer + " hat einen Kontostand von " + bs.getKontostand(kontonummer));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package persistence;
|
||||
|
||||
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 de.hs_mannheim.informatik.bank.domain.Bank;
|
||||
|
||||
public class BankSerializer {
|
||||
|
||||
public static void saveToFile(String filename, Bank bank) {
|
||||
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(filename)))) {
|
||||
oos.writeObject(bank);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Bank readFromFile(String filename) {
|
||||
try(ObjectInputStream ooi = new ObjectInputStream(new FileInputStream(new File(filename)))) {
|
||||
try {
|
||||
return (Bank) ooi.readObject(); // schauen welche Exceptions geworfen werden
|
||||
} catch (ClassNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package persistence;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class BankSerializer2 {
|
||||
|
||||
|
||||
File inFile = new File ("C:/Users/mehta/OneDrive/Masaüstü/PR1_Inhalt.txt");
|
||||
File outFile = new File ("C:/Users/mehta/OneDrive/Masaüstü/PR1_Inhalt-test.txt");
|
||||
|
||||
|
||||
|
||||
public static void inFileStream(File in, File out) {
|
||||
|
||||
InputStream inStream= null;
|
||||
OutputStream outStream = null;
|
||||
|
||||
try {
|
||||
inStream = new FileInputStream(in);
|
||||
outStream = new FileOutputStream(out);
|
||||
|
||||
int input;
|
||||
while((input = inStream.read())!= -1 ){
|
||||
outStream.write(input);
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
}finally {
|
||||
try {
|
||||
inStream.close();
|
||||
outStream.close();
|
||||
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue