View Javadoc

1   package com.arcmind.jsfquickstart.controller;
2   
3   import com.arcmind.jsfquickstart.model.Calculator;
4   
5   
6   /***
7    * Calculator Controller
8    *
9    * @author $author$
10   * @version $Revision$
11   */
12  public class CalculatorConroller {
13      //~ Instance fields --------------------------------------------------------
14  
15      /***
16       * Repressent the model object.
17       */
18      private Calculator calculator = new Calculator();
19  
20      /*** First number used in operation. */
21      private int firstNumber = 0;
22  
23      /*** Result of operation on first number and second number. */
24      private int result = 0;
25  
26      /*** Second number used in operation. */
27      private int secondNumber = 0;
28  
29      //~ Constructors -----------------------------------------------------------
30  
31      /***
32       * Creates a new CalculatorConroller object.
33       */
34      public CalculatorConroller() {
35          super();
36      }
37  
38      //~ Methods ----------------------------------------------------------------
39  
40      /***
41       * Calculator, this class represent the model.
42       *
43       * @param aCalculator The calculator to set.
44       */
45      public void setCalculator(Calculator aCalculator) {
46          this.calculator = aCalculator;
47      }
48  
49      /***
50       * First Number property
51       *
52       * @param aFirstNumber first number
53       */
54      public void setFirstNumber(int aFirstNumber) {
55          this.firstNumber = aFirstNumber;
56      }
57  
58      /***
59       * First number property
60       *
61       * @return First number.
62       */
63      public int getFirstNumber() {
64          return firstNumber;
65      }
66  
67      /***
68       * Result of the operation on the first two numbers.
69       *
70       * @return Second Number.
71       */
72      public int getResult() {
73          return result;
74      }
75  
76      /***
77       * Second number property
78       *
79       * @param aSecondNumber Second number.
80       */
81      public void setSecondNumber(int aSecondNumber) {
82          this.secondNumber = aSecondNumber;
83      }
84  
85      /***
86       * Get second number.
87       *
88       * @return Second number.
89       */
90      public int getSecondNumber() {
91          return secondNumber;
92      }
93  
94      /***
95       * Adds the first number and second number together.
96       *
97       * @return next logical outcome.
98       */
99      public String add() {
100 
101         result = calculator.add(firstNumber, secondNumber);
102 
103         return "success";
104     }
105 
106     /***
107      * Multiplies the first number and second number together.
108      *
109      * @return next logical outcome.
110      */
111     public String multiply() {
112 
113         result = calculator.multiply(firstNumber, secondNumber);
114 
115         return "success";
116     }
117 }