Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package aula31.privateandpublic.lab.calculator;
- public class Calculator {
- private int value1;
- private int value2;
- public String getSum(){
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(String.format("%d + %d = %d",this.getValue1(), this.getValue2(),
- this.getValue1() + this.getValue2()));
- return stringBuilder.toString();
- }
- public String getSubtraction(){
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(String.format("%d - %d = %d",this.getValue1(), this.getValue2(),
- this.getValue1() - this.getValue2()));
- return stringBuilder.toString();
- }
- public String getMultiply(){
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(String.format("%d * %d = %d",this.getValue1(), this.getValue2(),
- this.getValue1() * this.getValue2()));
- return stringBuilder.toString();
- }
- public String getDivison(){
- StringBuilder stringBuilder = new StringBuilder();
- try {
- stringBuilder.append(String.format("%d / %d = %d",this.getValue1(), this.getValue2(),
- this.getValue1() / this.getValue2()));
- return stringBuilder.toString();
- }catch (Exception e){
- e.printStackTrace();
- }
- return "erro";
- }
- public int getValue1() {
- return value1;
- }
- public Calculator setValue1(int value1) {
- this.value1 = value1;
- return this;
- }
- public int getValue2() {
- return value2;
- }
- public Calculator setValue2(int value2) {
- this.value2 = value2;
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement