diff options
Diffstat (limited to 'src/de/fhswf/in/inf/java1/aufgabe5/Konto.java')
| -rw-r--r-- | src/de/fhswf/in/inf/java1/aufgabe5/Konto.java | 174 |
1 files changed, 99 insertions, 75 deletions
diff --git a/src/de/fhswf/in/inf/java1/aufgabe5/Konto.java b/src/de/fhswf/in/inf/java1/aufgabe5/Konto.java index 3d3aed5..24194b3 100644 --- a/src/de/fhswf/in/inf/java1/aufgabe5/Konto.java +++ b/src/de/fhswf/in/inf/java1/aufgabe5/Konto.java @@ -1,75 +1,99 @@ -/**
- *
- */
-package de.fhswf.in.inf.java1.aufgabe5;
-
-import java.math.BigDecimal;
-
-/**
- * TODO Add comment here
- *
- * @author $Author: $
- * @version $Revision: $, $Date: $ UTC
- */
-public class Konto
-{
-
- private BigDecimal guthaben;
-
- private BigDecimal dispo;
-
- private Person besitzer;
-
- /**
- * TODO Add constructor comment here
- *
- * @param besitzer
- * Owner of the account
- * @param dispo
- * Dispo of the account
- * @param guthaben
- * Initial balance of the account
- */
- public Konto(Person besitzer, BigDecimal dispo, BigDecimal guthaben)
- {
-
- if (besitzer == null)
- {
- throw new IllegalArgumentException("Besitzer can't be null");
- }
- if (dispo == null)
- {
- throw new IllegalArgumentException("Dispo can't be null");
- }
- if (guthaben == null)
- {
- throw new IllegalArgumentException("Guthaben can't be null");
- }
-
- this.besitzer = besitzer;
- this.dispo = dispo;
- this.guthaben = guthaben;
-
- }
-
- /**
- * TODO Add method comment here
- *
- * @param betrag
- */
- public void abheben(BigDecimal betrag)
- {
-
- }
-
- /**
- * TODO Add method comment here
- *
- * @param betrag
- */
- public void einzahlen(BigDecimal betrag)
- {
-
- }
-
-}
+/** + * + */ +package de.fhswf.in.inf.java1.aufgabe5; + +import java.math.BigDecimal; + +/** + * An implementation of the Konto class wich 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 + * @param guthaben + * Initial balance of the account + */ + public Konto(Person besitzer, BigDecimal dispo, BigDecimal guthaben) + { + + if (besitzer == null) + { + throw new IllegalArgumentException("Besitzer can't be null"); + } + if (dispo == null) + { + throw new IllegalArgumentException("Dispo can't be null"); + } + if (guthaben == null) + { + throw new IllegalArgumentException("Guthaben can't be null"); + } + + this.besitzer = besitzer; + this.dispo = dispo; + this.guthaben = guthaben; + + } + + /** + * 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); + } + +} |
