Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package bean;
- import javax.faces.bean.ManagedBean;
- import javax.faces.bean.RequestScoped;
- /**
- *
- * @author cmpkwhit
- */
- @ManagedBean
- @RequestScoped
- public class CalculatorBean {
- /**
- * Creates a new instance of CalculatorBean
- */
- public CalculatorBean() {
- }
- //properties
- private Integer firstOperand=null;
- private Integer secondOperand=null;
- private Integer thirdOperand=null;
- private Integer fourthOperand=null;
- private Integer operation=null;
- private Integer operation2 = null;
- private Integer sum = null;
- private Integer result=null;
- private Integer result1 = null;
- //methods
- public Integer getFirstOperand() {
- return firstOperand;
- }
- public Integer getResult1() {
- return result1;
- }
- public void setResult1(Integer result1) {
- this.result1 = result1;
- }
- public void setFirstOperand(Integer firstOperand) {
- this.firstOperand = firstOperand;
- }
- public Integer getSecondOperand() {
- return secondOperand;
- }
- public void setSecondOperand(Integer secondOperand) {
- this.secondOperand = secondOperand;
- }
- public Integer getOperation() {
- return operation;
- }
- public void setOperation(Integer operand) {
- this.operation = operand;
- }
- public Integer getResult() {
- return result;
- }
- public void setResult(Integer result) {
- this.result = result;
- }
- public Integer getOperation2() {
- return operation2;
- }
- public void setOperation2(Integer operation2) {
- this.operation2 = operation2;
- }
- public Integer getThirdOperand() {
- return thirdOperand;
- }
- public void setThirdOperand(Integer thirdOperand) {
- this.thirdOperand = thirdOperand;
- }
- public Integer getFourthOperand() {
- return fourthOperand;
- }
- public void setFourthOperand(Integer fourthOperand) {
- this.fourthOperand = fourthOperand;
- }
- public Integer getSum() {
- return sum;
- }
- public void setSum(Integer sum) {
- this.sum = sum;
- }
- public String calculate() {
- if(this.operation!=null && this.firstOperand !=null && this.secondOperand !=null) {
- if(this.operation==1) this.result1=this.firstOperand+this.secondOperand;
- if(this.operation==2) this.result1=this.firstOperand-this.secondOperand;
- if(this.operation==3) this.result1=this.firstOperand*this.secondOperand;
- if(this.operation==4) this.result1=this.firstOperand/this.secondOperand;
- setSum(result1);
- calculateNext();
- }
- return null;
- }
- public String calculateNext() {
- if(this.operation2!=null && this.sum !=null && this.thirdOperand !=null) {
- if(this.operation2==1) this.result=this.sum+this.thirdOperand;
- if(this.operation2==2) this.result=this.sum-this.thirdOperand;
- if(this.operation2==3) this.result=this.sum*this.thirdOperand;
- if(this.operation2==4) this.result=this.sum/this.thirdOperand;
- }
- return null;
- }
- public String about() {
- return "about";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement