KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > samples > bank > Account


1 /*
2   Renaud Pawlak, pawlak@cnam.fr, CEDRIC Laboratory, Paris, France.
3   Lionel Seinturier, Lionel.Seinturier@lip6.fr, LIP6, Paris, France.
4
5   JAC-Core is free software. You can redistribute it and/or modify it
6   under the terms of the GNU Library General Public License as
7   published by the Free Software Foundation.
8   
9   JAC-Core is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13   This work uses the Javassist system - Copyright (c) 1999-2000
14   Shigeru Chiba, University of Tsukuba, Japan. All Rights Reserved. */

15
16 package org.objectweb.jac.samples.bank;
17
18 import org.objectweb.jac.samples.contacts.Person;
19
20 /**
21  * Defines the accounts in the banks of the bank sample.<p>
22  *
23  * Accounts belong to banks.<p>
24  *
25  * @see Bank
26  *
27  * @author <a HREF="mailto:maxime@aopsys.com">Maxime Pawlak</a>
28  * @author <a HREF="mailto:pawlak@cnam.fr">Renaud Pawlak</a>
29  */

30
31 public class Account {
32
33    /** allowed deficit */
34    protected double allowedDeficit = 0;
35    
36    /** The current balance of the account. */
37    protected double balance;
38
39    /** The account number. */
40    protected long accountNumber;
41
42    Bank bank=null;
43    
44    public void setBank(Bank bank) {
45       this.bank=bank;
46    }
47
48    /** the owner */
49    Person owner;
50
51    public Person getOwner() {
52       return owner;
53    }
54
55    public void setOwner(Person owner) {
56       this.owner=owner;
57       if( bank != null ) {
58          bank.addUser(owner);
59       }
60    }
61
62    public void setAllowedDeficit(double allowedDeficit) {
63       this.allowedDeficit = allowedDeficit;
64    }
65
66    public double getAllowedDeficit() {
67       return allowedDeficit;
68    }
69
70    /**
71     * Creates a new account.<p>
72     *
73     * @param accountNumber the new account number
74     * @param bankNumber the bank number the new account will belong to
75     */

76
77    public Account(long accountNumber){
78       this.accountNumber = accountNumber;
79       balance = 0;
80    }
81
82    /**
83     * Returns a textual representation of the account.<p>
84     *
85     * @return a textual representation */

86
87    public String JavaDoc toString() {
88       return accountNumber+" ("+balance+")";
89    }
90
91    /**
92     * Credits the account balance with the given amount.<p>
93     *
94     * @param amount the amount to credit with
95     */

96
97    public void credit(double amount) {
98       if( balance + amount > allowedDeficit ) {
99          balance += amount;
100       } else {
101          throw new RuntimeException JavaDoc("Allowed deficit is not sufficient for account "+this);
102       }
103    }
104
105    /**
106     * Debits the account balance with the given amount.<p>
107     *
108     * @param amount the amount to debit with
109     */

110
111    public void debit(double amount) {
112       if( balance - amount > allowedDeficit ) {
113          balance -= amount;
114       } else {
115          throw new RuntimeException JavaDoc("Allowed deficit is not sufficient for account "+this);
116       }
117    }
118
119    /**
120     * Gets the current balance of the account.<p>
121     *
122     * @return the balance */

123  
124    public double getBalance(){
125       return balance;
126    }
127
128    public void setBalance(double balance){
129       this.balance=balance;
130    }
131
132    /**
133     * Gets the account number.<p>
134     *
135     * @return the account number */

136
137    public long getAccountNumber(){
138       return accountNumber;
139    }
140
141    public void setAccountNumber(long number) {
142       this.accountNumber = number;
143    }
144
145 }
146
Popular Tags