View Javadoc

1   /**
2    * 
3    */
4   package org.sourceforge.jemm.sample.demo1.model;
5   
6   import org.sourceforge.jemm.Entity;
7   import org.sourceforge.jemm.lifecycle.ConstructorLifecycle;
8   import org.sourceforge.jemm.lifecycle.ShadowUserObject;
9   
10  /**
11   * A Savings account owned by Person (extension of basic Account to include
12   * interest handling.).
13   * 
14   * @author Paul Keeble
15   */
16  @Entity
17  public class SavingsAccount extends Account {
18  	
19  	double lastInterestAmount;
20  
21  	/**
22  	 * Create a SavingsAccount with an initial balance of 0.
23  	 */
24  	public SavingsAccount() {
25  		ConstructorLifecycle.preConstructor(SavingsAccount.class.getName());
26  		ConstructorLifecycle.beginConstructor(this);
27  		try {
28  			lastInterestAmount = 0;
29  			ConstructorLifecycle.endConstructor(this); 
30  		}catch(Throwable t) {
31  			ConstructorLifecycle.failedConstructor(this);
32  			//would in the real program throw t not a RuntimeException
33  			throw new RuntimeException(t);
34  		}
35  	}
36  	
37      public SavingsAccount(ShadowUserObject jemmOIF) {
38          super(jemmOIF);
39      }
40  
41  	/**
42  	 * Create a SavingsAccount with the given initial balance.
43  	 * 
44  	 * @param initialBalance
45  	 *            The account initial balance.
46  	 */
47  	public SavingsAccount(double initialBalance) {
48  		
49  		super(initialBalance);
50  		ConstructorLifecycle.preConstructor(SavingsAccount.class.getName());
51  		ConstructorLifecycle.beginConstructor(this);
52  
53  		try {
54  			ConstructorLifecycle.endConstructor(this); 
55  		}catch(Throwable t) {
56  			ConstructorLifecycle.failedConstructor(this);
57  			//would in the real program throw t not a RuntimeException
58  			throw new RuntimeException(t);
59  		}
60  	}
61  
62  	/**
63  	 * Add yearly interest to the account using the given interest rate.
64  	 * 
65  	 * @param interestRate
66  	 *            The yearly interest rate to add.
67  	 */
68  	public void addInterest(double interestRate) {
69  		jemmOIF.entityEntered("org.sourceforge.jemm.sample.demo1.model.SavingsAccount#addInterest (D)V");
70  		jemmOIF.beginLock();
71  		try {
72  			lastInterestAmount = balance * interestRate / 100;
73  			balance = balance + lastInterestAmount;
74  		} finally {
75  			jemmOIF.endLock();
76  			jemmOIF.entityExited("org.sourceforge.jemm.sample.demo1.model.SavingsAccount#addInterest (D)V");
77  		}
78  	}
79  }