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