Advertisement
NelloRizzo

Calculator

May 22nd, 2020
1,588
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package corso.java.springapp.business;
  2.  
  3. public class Calculator {
  4.     private float first;
  5.     private float second;
  6.     private float result;
  7.     private char op;
  8.  
  9.     public Calculator(float first, float second, char op) {
  10.         this.first = first;
  11.         this.second = second;
  12.         this.op = op;
  13.         execute(op);
  14.     }
  15.  
  16.     private void execute(char operation) {
  17.         switch (operation) {
  18.         case '+':
  19.             result = first + second;
  20.             break;
  21.         case '-':
  22.             result = first - second;
  23.             break;
  24.         case '*':
  25.             result = first * second;
  26.             break;
  27.         case '/':
  28.             result = first / second;
  29.             break;
  30.         default:
  31.             break;
  32.         }
  33.     }
  34.  
  35.     public float getFirst() {
  36.         return first;
  37.     }
  38.  
  39.     public void setFirst(float first) {
  40.         this.first = first;
  41.     }
  42.  
  43.     public float getSecond() {
  44.         return second;
  45.     }
  46.  
  47.     public void setSecond(float second) {
  48.         this.second = second;
  49.     }
  50.  
  51.     public float getResult() {
  52.         return result;
  53.     }
  54.  
  55.     public void setResult(float result) {
  56.         this.result = result;
  57.     }
  58.  
  59.     public char getOp() {
  60.         return op;
  61.     }
  62.  
  63.     public void setOp(char op) {
  64.         this.op = op;
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement