summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe05/Konto.java
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2014-12-07 19:15:58 +0100
committerStefan Suhren <suhren.stefan@fh-swf.de>2014-12-07 19:18:03 +0100
commit9acea903216dbe371dd7b41cbf23b46a5732bcb4 (patch)
tree5a61491ad22e470db8151d2e07f163b011c72d6e /src/de/fhswf/in/inf/java1/aufgabe05/Konto.java
parent8a53a8fca255e4a84ca0e35dac925a223738b98a (diff)
downloadJava1-9acea903216dbe371dd7b41cbf23b46a5732bcb4.tar.gz
Java1-9acea903216dbe371dd7b41cbf23b46a5732bcb4.zip
Refactored the packagenames fo better sorting
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe05/Konto.java')
-rw-r--r--src/de/fhswf/in/inf/java1/aufgabe05/Konto.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe05/Konto.java b/src/de/fhswf/in/inf/java1/aufgabe05/Konto.java
new file mode 100644
index 0000000..235f9af
--- /dev/null
+++ b/src/de/fhswf/in/inf/java1/aufgabe05/Konto.java
@@ -0,0 +1,119 @@
+/**
+ *
+ */
+package de.fhswf.in.inf.java1.aufgabe05;
+
+import java.math.BigDecimal;
+
+/**
+ * An implementation of the Konto class which represents a bank account.
+ *
+ * @author $Author: $
+ * @version $Revision: $, $Date: $ UTC
+ */
+public class Konto
+{
+
+ private BigDecimal guthaben;
+
+ private BigDecimal dispo;
+
+ private Person besitzer;
+
+ /**
+ * Creates an account with an owner, a dispo and an initial balance.
+ *
+ * @param besitzer
+ * Owner of the account
+ * @param dispo
+ * Dispo of the account
+ */
+ public Konto(Person besitzer, BigDecimal dispo)
+ {
+
+ if (besitzer == null)
+ {
+ throw new IllegalArgumentException("Besitzer can't be null");
+ }
+ if (dispo == null)
+ {
+ throw new IllegalArgumentException("Dispo can't be null");
+ }
+ if (dispo.compareTo(BigDecimal.ZERO) < 0)
+ {
+ throw new IllegalArgumentException("Dispo can't be negative");
+ }
+
+ this.besitzer = besitzer;
+ this.dispo = dispo;
+ this.guthaben = new BigDecimal(0);
+
+ this.besitzer.addKonto(this);
+
+ }
+
+ /**
+ * Function for withdrawing money from the account.
+ *
+ * @param betrag
+ * Amount of cash to be withdrawn
+ */
+ public void abheben(BigDecimal betrag)
+ {
+ if (betrag == null)
+ {
+ throw new IllegalArgumentException("Betrag can't be null");
+ }
+ if (betrag.compareTo(BigDecimal.ZERO) < 0)
+ {
+ throw new IllegalArgumentException("Betrag can't be negative");
+ }
+ if (guthaben.add(dispo).compareTo(betrag) < 0)
+ {
+ throw new IllegalArgumentException("Betrag surpasses dispo limit");
+ }
+
+ guthaben = guthaben.subtract(betrag);
+ }
+
+ /**
+ * Function to deposit money into the account.
+ *
+ * @param betrag
+ * Amount of cash to be disposed
+ */
+ public void einzahlen(BigDecimal betrag)
+ {
+ if (betrag == null)
+ {
+ throw new IllegalArgumentException("Betrag can't be null");
+ }
+ if (betrag.compareTo(BigDecimal.ZERO) < 0)
+ {
+ throw new IllegalArgumentException("Betrag can't be negative");
+ }
+
+ guthaben = guthaben.add(betrag);
+ }
+
+ /**
+ * Returns the actual balance.
+ *
+ * @return Returns the actual balance.
+ */
+ public BigDecimal getKontostand()
+ {
+ return guthaben;
+ }
+
+ /**
+ * Just to get the owners name.
+ *
+ * @return Returns the owners name.
+ */
+ public Person getBesitzer()
+ {
+ return besitzer;
+ }
+
+}