Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package bean;
  8.  
  9. import javax.faces.bean.ManagedBean;
  10. import javax.faces.bean.RequestScoped;
  11.  
  12. /**
  13. *
  14. * @author cmpkwhit
  15. */
  16. @ManagedBean
  17. @RequestScoped
  18. public class CalculatorBean {
  19.  
  20. /**
  21. * Creates a new instance of CalculatorBean
  22. */
  23. public CalculatorBean() {
  24. }
  25. //properties
  26. private Integer firstOperand=null;
  27. private Integer secondOperand=null;
  28. private Integer thirdOperand=null;
  29. private Integer fourthOperand=null;
  30. private Integer operation=null;
  31. private Integer operation2 = null;
  32. private Integer sum = null;
  33. private Integer result=null;
  34. private Integer result1 = null;
  35.  
  36.  
  37.  
  38. //methods
  39. public Integer getFirstOperand() {
  40. return firstOperand;
  41. }
  42.  
  43. public Integer getResult1() {
  44. return result1;
  45. }
  46.  
  47. public void setResult1(Integer result1) {
  48. this.result1 = result1;
  49. }
  50.  
  51. public void setFirstOperand(Integer firstOperand) {
  52. this.firstOperand = firstOperand;
  53. }
  54.  
  55. public Integer getSecondOperand() {
  56. return secondOperand;
  57. }
  58.  
  59. public void setSecondOperand(Integer secondOperand) {
  60. this.secondOperand = secondOperand;
  61. }
  62.  
  63. public Integer getOperation() {
  64. return operation;
  65. }
  66.  
  67. public void setOperation(Integer operand) {
  68. this.operation = operand;
  69. }
  70.  
  71. public Integer getResult() {
  72. return result;
  73. }
  74.  
  75. public void setResult(Integer result) {
  76. this.result = result;
  77. }
  78.  
  79. public Integer getOperation2() {
  80. return operation2;
  81. }
  82.  
  83. public void setOperation2(Integer operation2) {
  84. this.operation2 = operation2;
  85. }
  86.  
  87.  
  88. public Integer getThirdOperand() {
  89. return thirdOperand;
  90. }
  91.  
  92. public void setThirdOperand(Integer thirdOperand) {
  93. this.thirdOperand = thirdOperand;
  94. }
  95.  
  96. public Integer getFourthOperand() {
  97. return fourthOperand;
  98. }
  99.  
  100. public void setFourthOperand(Integer fourthOperand) {
  101. this.fourthOperand = fourthOperand;
  102. }
  103.  
  104. public Integer getSum() {
  105. return sum;
  106. }
  107.  
  108. public void setSum(Integer sum) {
  109. this.sum = sum;
  110. }
  111.  
  112. public String calculate() {
  113. if(this.operation!=null && this.firstOperand !=null && this.secondOperand !=null) {
  114. if(this.operation==1) this.result1=this.firstOperand+this.secondOperand;
  115. if(this.operation==2) this.result1=this.firstOperand-this.secondOperand;
  116. if(this.operation==3) this.result1=this.firstOperand*this.secondOperand;
  117. if(this.operation==4) this.result1=this.firstOperand/this.secondOperand;
  118. setSum(result1);
  119. calculateNext();
  120. }
  121. return null;
  122. }
  123.  
  124. public String calculateNext() {
  125. if(this.operation2!=null && this.sum !=null && this.thirdOperand !=null) {
  126. if(this.operation2==1) this.result=this.sum+this.thirdOperand;
  127. if(this.operation2==2) this.result=this.sum-this.thirdOperand;
  128. if(this.operation2==3) this.result=this.sum*this.thirdOperand;
  129. if(this.operation2==4) this.result=this.sum/this.thirdOperand;
  130. }
  131. return null;
  132. }
  133.  
  134. public String about() {
  135. return "about";
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement