`SessionCalculator.java`
`01 package trail.lifecycle; 02 03 import javax.ejb.*; 04 import java.util.*; 05 import java.io.Serializable; 06 07 @Stateful 08 public class SessionCalculator implements Calculator, Serializable { 09 10 public ArrayList <Integer> starts, ends; 11 public ArrayList <Double> growthrates, savings, results; 12 13 @PostConstruct 14 public void initialize () { 15 System.err.println("Init is called"); 16 starts = new ArrayList <Integer> (); 17 ends = new ArrayList <Integer> (); 18 growthrates = new ArrayList <Double> (); 19 savings = new ArrayList <Double> (); 20 results = new ArrayList <Double> (); 21 22 SessionRecord.totalSess++; 23 SessionRecord.activeSess++; 24 } 25 26 @PreDestroy 27 public void exit () { 28 System.err.println("exit is called"); 29 SessionRecord.activeSess--; 30 } 31 32 @PrePassivate 33 public void serialize () { 34 System.err.println("serialize is called"); 35 SessionRecord.pausedSess++; 36 } 37 38 @PostActivate 39 public void activate () { 40 System.err.println("activate is called"); 41 SessionRecord.pausedSess--; 42 } 43 44 @Remove 45 public void stopSession () { 46 // Call to this method signals the container 47 // to remove this bean instance and terminates 48 // the session. 49 } 50 51 public double calculate (int start, int end, double growthrate, double saving) { 52 double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); 53 double result = saving * 12. * (tmp - 1) / growthrate; 54 55 starts.add(Integer.valueOf(start)); 56 ends.add(Integer.valueOf(end)); 57 growthrates.add(Double.valueOf(growthrate)); 58 savings.add(Double.valueOf(saving)); 59 results.add(Double.valueOf(result)); 60 61 return result; 62 } 63 64 public ArrayList <Integer> getStarts () { 65 return starts; 66 } 67 68 public ArrayList <Integer> getEnds () { 69 return ends; 70 } 71 72 public ArrayList <Double> getGrowthrates () { 73 return growthrates; 74 } 75 76 public ArrayList <Double> getSavings () { 77 return savings; 78 } 79 80 public ArrayList <Double> getResults () { 81 return results; 82 } 83 84 }`