`CalculatorMBean.java`
`01 package trail.jmx; 02 03 import org.jboss.annotation.ejb.Service; 04 import org.jboss.annotation.ejb.Management; 05 06 @Service (objectName="trail:service=calculator") 07 @Management(Calculator.class) 08 public class CalculatorMBean implements Calculator { 09 10 double growthrate; 11 12 public void setGrowthrate (double growthrate) { 13 this.growthrate = growthrate; 14 } 15 16 public double getGrowthrate () { 17 return growthrate; 18 } 19 20 public double calculate (int start, int end, double saving) { 21 double tmp = Math.pow(1. + growthrate / 12., 12. * (end - start) + 1); 22 return saving * 12. * (tmp - 1) / growthrate; 23 } 24 25 // Lifecycle methods 26 public void create() throws Exception { 27 growthrate = 0.08; 28 System.out.println("Calculator - Creating"); 29 } 30 31 public void destroy() { 32 System.out.println("Calculator - Destroying"); 33 } 34 35 }`