Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None | 0 0
  1. package aula31.privateandpublic.lab.calculator;
  2.  
  3. public class Calculator {
  4.  
  5.     private int value1;
  6.     private int value2;
  7.  
  8.     public String getSum(){
  9.  
  10.         StringBuilder stringBuilder = new StringBuilder();
  11.  
  12.         stringBuilder.append(String.format("%d + %d = %d",this.getValue1(), this.getValue2(),
  13.                 this.getValue1() + this.getValue2()));
  14.  
  15.         return  stringBuilder.toString();
  16.     }
  17.  
  18.     public String getSubtraction(){
  19.  
  20.         StringBuilder stringBuilder = new StringBuilder();
  21.  
  22.         stringBuilder.append(String.format("%d - %d = %d",this.getValue1(), this.getValue2(),
  23.                 this.getValue1() - this.getValue2()));
  24.  
  25.         return  stringBuilder.toString();
  26.     }
  27.  
  28.     public String getMultiply(){
  29.  
  30.         StringBuilder stringBuilder = new StringBuilder();
  31.  
  32.         stringBuilder.append(String.format("%d * %d = %d",this.getValue1(), this.getValue2(),
  33.                 this.getValue1() * this.getValue2()));
  34.  
  35.         return stringBuilder.toString();
  36.     }
  37.  
  38.     public String getDivison(){
  39.  
  40.         StringBuilder stringBuilder = new StringBuilder();
  41.  
  42.         try {
  43.  
  44.             stringBuilder.append(String.format("%d / %d = %d",this.getValue1(), this.getValue2(),
  45.                     this.getValue1() / this.getValue2()));
  46.  
  47.             return stringBuilder.toString();
  48.  
  49.         }catch (Exception e){
  50.             e.printStackTrace();
  51.         }
  52.         return "erro";
  53.     }
  54.  
  55.     public int getValue1() {
  56.         return value1;
  57.     }
  58.  
  59.     public Calculator setValue1(int value1) {
  60.         this.value1 = value1;
  61.         return this;
  62.     }
  63.  
  64.     public int getValue2() {
  65.         return value2;
  66.     }
  67.  
  68.     public Calculator setValue2(int value2) {
  69.         this.value2 = value2;
  70.         return this;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement