Java Data Objects (JDO)

Creating a Simple Banking Application

Gopalan Suresh Raj

Note
To work with any of these samples, you will need the following:
.........................................JDK 1.2 or higher (I use JDK 1.3.1)
.........................................PE:JTM - The Productivity Environment for JavaTM (from HYWY Software Corporation)

 

The following file should be located in the Classes Folder that you identified in PE:J

com/hywy/samples/bank/Account.java
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:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
/**
  * author: Gopalan Suresh Raj
  * Copyright (c), 2002. All Rights Reserved.
  * URL: https://gsraj.tripod.com/
  * email: gopalan@gmx.net
  */


package com.hywy.samples.bank;

import java.util.Date;

/////////////////////////////
//  User added imports
/////////////////////////////
import java.util.Calendar;
import java.util.TimeZone;
/////////////////////////////

/**
*  Class Description for Account.java
*
*  @author: gopalan
*  @created date: Apr 16, 2002
*  @last modified date:
*  @version:
*
*/

public class Account {

  /** Attribute   accountType_ */
  protected int accountType_  ;


  /** Attribute   customerNames_ */
  protected java.lang.String customerNames_  ;


  /** Attribute   balance_ */
  protected int balance_  ;


  /** Attribute   openedOn_ */
  protected java.util.Date openedOn_  ;


  /** Attribute   INVALID_ACCOUNT_ */
  protected static int INVALID_ACCOUNT_  = -1  ;


  /** Attribute   CHECKING_ACCOUNT_ */
  protected static int CHECKING_ACCOUNT_  = 100  ;


  /** Attribute   SAVINGS_ACCOUNT_ */
  protected static int SAVINGS_ACCOUNT_  = 200  ;




  /** Constructor */
  public Account() {
    super();
    ///////////////////////////////////////////
    //// Start of User's Business Logic    ////
    ///////////////////////////////////////////
    this.accountType_ = INVALID_ACCOUNT_;
    ///////////////////////////////////////////
    ////   End of User's Business Logic    ////
    ///////////////////////////////////////////    
  }


  /** Methods Description */
  public int create(java.lang.String customerNames,
                    int startingBalance)
    throws java.lang.Exception {
    //return 0;
    ///////////////////////////////////////////
    //// Start of User's Business Logic    ////
    ///////////////////////////////////////////
    if(this.accountType_ == INVALID_ACCOUNT_) {
      throw new Exception("Invalid Account Type :"+this.accountType_);
    }
    if(startingBalance < 0) {
      throw new Exception("Invalid Starting Balance (in cents):" + startingBalance);
    }
    this.customerNames_ = customerNames;
    this.balance_ = startingBalance;
    this.openedOn_ = Calendar.getInstance(TimeZone.getTimeZone("GMT")).getTime();
    return this.balance_;
    ///////////////////////////////////////////
    ////   End of User's Business Logic    ////
    ///////////////////////////////////////////    
  }

  /** Methods Description */
  public int credit(int amount) throws java.lang.Exception {
    //return 0;
    ///////////////////////////////////////////
    //// Start of User's Business Logic    ////
    ///////////////////////////////////////////
    if(this.accountType_ == INVALID_ACCOUNT_) {
      throw new Exception("Invalid Account Type :"+this.accountType_);
    }
    if(amount < 0) {
      throw new Exception("Invalid Amount (in cents) :"+amount);
    }
    this.balance_ += amount;
    return this.balance_;
    ///////////////////////////////////////////
    ////   End of User's Business Logic    ////
    ///////////////////////////////////////////    
  }

  /** Methods Description */
  public int debit(int amount) throws java.lang.Exception {
    //return 0;
    ///////////////////////////////////////////
    //// Start of User's Business Logic    ////
    ///////////////////////////////////////////
    if(this.accountType_ == INVALID_ACCOUNT_) {
      throw new Exception("Invalid Account Type :"+this.accountType_);
    }
    if(amount < 0) {
      throw new Exception("Invalid Amount (in cents) :"+amount);
    }
    this.balance_ -= amount;
    return this.balance_;
    ///////////////////////////////////////////
    ////   End of User's Business Logic    ////
    ///////////////////////////////////////////    
  }

  /** Setter Method for field --> accountType_*/
  public void  setAccountType_(   int newAccountType_   ) {
    accountType_ = newAccountType_;
  }

  /** Accessor Method for field --> accountType_ */
  public int  getAccountType_(  ) {
    return accountType_;
  }

  /** Setter Method for field --> customerNames_*/
  public void  setCustomerNames_(   java.lang.String newCustomerNames_   ) {
    customerNames_ = newCustomerNames_;
  }

  /** Accessor Method for field --> customerNames_ */
  public java.lang.String  getCustomerNames_(  ) {
    return customerNames_;
  }

  /** Setter Method for field --> balance_*/
  public void  setBalance_(   int newBalance_   ) {
    balance_ = newBalance_;
  }

  /** Accessor Method for field --> balance_ */
  public int  getBalance_(  ) {
    return balance_;
  }

  /** Setter Method for field --> openedOn_*/
  public void  setOpenedOn_(   java.util.Date newOpenedOn_   ) {
    openedOn_ = newOpenedOn_;
  }

  /** Accessor Method for field --> openedOn_ */
  public java.util.Date  getOpenedOn_(  ) {
    return openedOn_;
  }

  /** Default toString() method */
  public java.lang.String  toString(  ) {
    StringBuffer strBuff = new StringBuffer();

    strBuff.append(" Account: ");
    strBuff.append(" accountType_= " + accountType_);
    strBuff.append(" customerNames_= " + customerNames_);
    strBuff.append(" balance_= " + balance_);
    strBuff.append(" openedOn_= " + openedOn_);

    return strBuff.toString();
  }
}

 

click here to go to
My JDO HomePage...

click here to go to
My Advanced Java Tutorial Page...

About the Author...
Gopalan Suresh Raj is a Software Architect, Developer and an active Author. He has co-authored a number of books including "Professional JMS", "Enterprise Java Computing-Applications and Architecture" and "The Awesome Power of JavaBeans". His expertise spans enterprise component architectures and distributed object computing. Visit him at his Web Cornucopia© site (https://gsraj.tripod.com/) or mail him at gopalan@gmx.net.

Go to the Component Engineering Cornucopia page

This site was developed and is maintained by Gopalan Suresh Raj

This page has been visited times since February 26,2002.

Last Updated : Feb 26, 2002

If you have any questions, comments, or problems regarding this site, please write to me I would love to hear from you.


Copyright (c) 1997-2002, Gopalan Suresh Raj - All rights reserved. Terms of use.

All products and companies mentioned at this site are trademarks of their respective owners.