Introducing the Spring Framework - Spring Framework in the Real World (Page 4 of 5 )
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:
SimpleCalculatorBean.java – POJO that wraps the logic for calculating simple interest.
bean.xml – The configuration file that contains details about the POJO
Client.java – The client for the simple interest calculation
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();
}
}
Next: Beans and Client >>
More Java Articles
More By A.P.Rajshekhar