summaryrefslogtreecommitdiffstats
path: root/src/de/fhswf/in/inf/java1/aufgabe05/Konto.java
blob: 235f9af4ec39c0fdf07c7cd5c594726430482321 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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;
   }

}