Test Commit

master
Alper Kaya 2022-10-10 13:33:14 +02:00
commit 06581fb698
10 changed files with 506 additions and 0 deletions

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>

181
Bank-Beispiel/.gitignore vendored 100644
View File

@ -0,0 +1,181 @@
# ---> 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

View File

@ -0,0 +1,17 @@
<?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>

View File

@ -0,0 +1,13 @@
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);
}
}

View File

@ -0,0 +1,30 @@
package de.hs_mannheim.informatik.bank.domain;
import java.util.Collection;
import java.util.HashMap;
public class Bank {
private String name;
private HashMap<Integer, Konto> konten = new HashMap<>();
public Bank(String name) {
this.name = name;
}
public void addKonto(Konto k) {
konten.put(k.getKontonummer(), k);
}
public String getName() {
return name;
}
public Collection<Konto> getKontenliste() {
return konten.values();
}
public Konto getKonto(int key) {
return konten.get(key);
}
}

View File

@ -0,0 +1,33 @@
package de.hs_mannheim.informatik.bank.domain;
public class Konto {
private static int kontozaehler = 0;
private int nummer;
private long stand = 0;
private String inhaber;
public Konto(String inhaber) {
nummer = 1000 + kontozaehler++;
this.inhaber = inhaber;
}
public long kontoEinzahlen(Konto k, long betrag) {
k.stand = k.stand + betrag;
return k.stand;
}
public int getKontonummer() {
return nummer;
}
public long getKontostand() {
return stand;
}
@Override
public String toString() {
return "Konto [nummer=" + nummer + ", inhaber=" + inhaber + "]";
}
}

View File

@ -0,0 +1,15 @@
package de.hs_mannheim.informatik.bank.domain;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class KontoTest {
@Test
void kontoEinzahlenTest() {
Konto k = new Konto("User");
k.kontoEinzahlen(k, 100);
assertEquals(150, k.kontoEinzahlen(k, 50));
}
}

View File

@ -0,0 +1,80 @@
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.Konto;
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 kontoStand(int kontonr) {
Konto k = bank.getKonto(kontonr);
long betrag = k.getKontostand();
if (betrag == 0)
return "0.00";
StringBuilder standKomma = new StringBuilder(Long.toString(betrag));
int posKomma = standKomma.length()-2;
standKomma = standKomma.insert(posKomma, '.');
return standKomma.toString();
}
public String kontoEinzahlen(String betrag, int kontonr) {
boolean komma = false;
// Schaut ob Betrag mit Komma (zB: 42.50)
for (char ch : betrag.toCharArray()) {
if (ch == '.')
komma = true;
}
if (!komma)
betrag = betrag + ".00";
long betrag_long = Long.parseLong(betrag.replace(".", ""));
Konto k = bank.getKonto(kontonr);
k.kontoEinzahlen(k, betrag_long);
// Betrag mit 2 Nachkommastellen für den User anzeigen lassen
StringBuilder standKomma = new StringBuilder(Long.toString(k.getKontostand()));
int posKomma = standKomma.length()-2;
standKomma = standKomma.insert(posKomma, '.');
return standKomma.toString();
}
public String kontoAbheben(String betrag, int kontonr) {
//code
return betrag;
}
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();
}
}

View File

@ -0,0 +1,22 @@
package de.hs_mannheim.informatik.bank.facade;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class BanksystemTest {
@Test
void kontoEinzahlenMitKommatest() {
Banksystem bs = new Banksystem("Testbank");
int kontonr = bs.kontoAnlegen("User");
assertEquals("42.50", bs.kontoEinzahlen("42.50", kontonr));
}
@Test
void kontoEinzahlenOhneKommatest() {
Banksystem bs = new Banksystem("Testbank2");
int kontonr = bs.kontoAnlegen("User2");
assertEquals("50.00", bs.kontoEinzahlen("50", kontonr));
}
}

View File

@ -0,0 +1,104 @@
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;
hauptmenue();
}
private void hauptmenue() {
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 -> Einzahlen");
System.out.println("4 -> Kontostand");
System.out.println("5 -> Abheben");
System.out.println("9 -> Beenden");
System.out.println();
System.out.print("> ");
int input = Integer.parseInt(sc.nextLine());
System.out.println();
switch(input) {
case 1: kontenAnzeigen(); break;
case 2: kontoAnlegen(); break;
case 3: kontoEinzahlen(); break;
case 4: kontoStand(); break;
//case 5: kontoAbheben() break;
case 9: break mainloop;
}
}
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();
int kontonummer = bs.kontoAnlegen(name);
System.out.println("Konto mit der Nummer " + kontonummer + " neu angelegt.");
}
private void kontoEinzahlen() {
//Kontonr und Betrag einlesen
System.out.println("Kontonummer: ");
int kontonr = sc.nextInt();
sc.nextLine();
System.out.println("Betrag: ");
String betrag = sc.nextLine();
String gesamt = bs.kontoEinzahlen(betrag, kontonr);
System.out.println("Neuer Kontostand: " + gesamt + "€.");
}
private void kontoAbheben() {
//Kontonr und Betrag einlesen
System.out.println("Kontonummer: ");
int kontonr = sc.nextInt();
sc.nextLine();
System.out.println("Betrag: ");
String betrag = sc.nextLine();
String gesamt = bs.kontoAbheben(betrag, kontonr);
System.out.println("Neuer Kontostand: " + gesamt + "€.");
}
private void kontoStand() {
//Kontonr einlesen
System.out.println("Kontonummer: ");
int kontonr = sc.nextInt();
sc.nextLine();
String gesamt = bs.kontoStand(kontonr);
System.out.println("Kontostand: " + gesamt + "€.");
}
}