`StatefulCalculator.java`
`01 package trail.sfsb; 02 03 import javax.ejb.*; 04 import java.util.*; 05 import java.io.Serializable; 06 07 @Stateful 08 public class StatefulCalculator implements Calculator, Serializable { 09 10 public ArrayList <Integer> starts = new ArrayList <Integer> (); 11 public ArrayList <Integer> ends = new ArrayList <Integer> (); 12 public ArrayList <Double> growthrates = new ArrayList <Double> (); 13 public ArrayList <Double> savings = new ArrayList <Double> (); 14 public ArrayList <Double> results = new ArrayList <Double> (); 15 16 /* 17 @PostConstruct 18 public void initialize () { 19 // System.err.println("Init is called"); 20 starts = new ArrayList <Integer> (); 21 ends = new ArrayList <Integer> (); 22 growthrates = new ArrayList <Double> (); 23 savings = new ArrayList <Double> (); 24 results = new ArrayList <Double> (); 25 } 26 */ 27 28 public double calculate (int start, int end, double growthrate, double saving) { 29 double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); 30 double result = saving * 12. * (tmp - 1) / growthrate; 31 32 starts.add(Integer.valueOf(start)); 33 ends.add(Integer.valueOf(end)); 34 growthrates.add(Double.valueOf(growthrate)); 35 savings.add(Double.valueOf(saving)); 36 results.add(Double.valueOf(result)); 37 38 return result; 39 } 40 41 public ArrayList <Integer> getStarts () { 42 return starts; 43 } 44 45 public ArrayList <Integer> getEnds () { 46 return ends; 47 } 48 49 public ArrayList <Double> getGrowthrates () { 50 return growthrates; 51 } 52 53 public ArrayList <Double> getSavings () { 54 return savings; 55 } 56 57 public ArrayList <Double> getResults () { 58 return results; 59 } 60 61 }`