Java & J2EE Page 4 - Introducing the Spring Framework |
In the previous section, the steps required to use the IoC component of the Spring Framework were enumerated. Now, it's time to develop a real world example based upon these steps. The application we are going to develop will wrap the logic to calculate simple interest. The application will have the following files:
First comes the SimpleCalculatorBean.java. It is a simple Java Bean that has getters and setters for rate, years, and principle. It also contains the calculate method for calculating simple interest. Here is the code: package org.me; class SimpleInterestCalculatorBean{ float years; float principle; float rate; SimpleInterestCalculatorBean(){ } public void setYears(float years){ this.years=years; } public float getYears(){ return years; }
public void setPrinciple(float principle){ this. principle = principle; } public float getPrinciple(){ return principle; }
public void setRate(float rate){ this. rate=rate; }
public float calculate(){ return (float)((principle*rate*years)/100); } public float getInterest(){ return calculate(); }
}
blog comments powered by Disqus |
|
|
|
|
|
|
|