Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I do this on the code below: package part2.code; import part1.code.Add;

ID: 3681880 • Letter: H

Question

How can I do this on the code below:

package part2.code;

import part1.code.Add;
import part2.operations.BinaryOperation;
import part2.user_interface.CalculatorUI;

public class Calculator {
    
    private int _value;
    private CalculatorUI _ui;
    private BinaryOperation _bo;
    private Add _addOperator;
    private Subtract _subOperator;
    private Multiply _mulOperator;
    private Divide _divOperator;

    
    
    
    public Calculator(CalculatorUI calculatorUI) {
        _ui = calculatorUI;
        _value = 0;
    }

    public void digit_0_keyPressed() {
        _value = _value * 10 + 0;
        _ui.updateDisplay();
    }
    public void digit_1_keyPressed() {
        _value = _value * 10 + 1;
        _ui.updateDisplay();
    }
    public void digit_2_keyPressed() {
        _value = _value * 10 + 2;
        _ui.updateDisplay();
    }
    public void digit_3_keyPressed() {
        _value = _value * 10 + 3;
        _ui.updateDisplay();
    }
    public void digit_4_keyPressed() {
        _value = _value * 10 + 4;
        _ui.updateDisplay();
    }
    public void digit_5_keyPressed() {
        _value = _value * 10 + 5;
        _ui.updateDisplay();
    }
    public void digit_6_keyPressed() {
        _value = _value * 10 + 6;
        _ui.updateDisplay();
    }
    public void digit_7_keyPressed() {
        _value = _value * 10 + 7;
        _ui.updateDisplay();
    }
    public void digit_8_keyPressed() {
        _value = _value * 10 + 8;
        _ui.updateDisplay();
    }
    public void digit_9_keyPressed() {
        _value = _value * 10 + 9;
        _ui.updateDisplay();
    }
    public void clear_keyPressed() {
        _value = 0;
        _ui.updateDisplay();
    }
    public int getValue() {
        return _value;
    }
    public void divide_keyPressed() {
        // TODO Define this method
        _divOperator = new Divide(_value);
        _value = 0;
    }
    public void multiply_keyPressed() {
        // TODO Define this method
        _mulOperator = new Multiply(_value);
        _value = 0;
    }
    public void subtract_keyPressed() {
        // TODO Define this method
        _subOperator = new Subtract(_value);
        _value = 0;
    }
    public void add_keyPressed() {
        // TODO Define this method
        _addOperator = new Add(_value);
        _value = 0;
    }
    public void equal_keyPressed() {
        // TODO Define this method
        _value = _addOperator.perform(_value);
        _ui.updateDisplay();

    }

}

The other one is

package part2.operations;

public class Add implements BinaryOperation {

   @Override
   public int perform(int arg) {
       // TODO Auto-generated method stub
       return 0;
   }


}

Microsoft Word Lab07.docx - Lab07.pdf - Mozilla Firefox Microsoft Word-Lab x e Chegg study | Guide x | + www.cse.buffalo.edu/faculty/alphonce/cse1 15/work/Lab07.pdf 6 of 6 c | | a Search Page - + Automatic Zoom# Now you want to do this for the remaining three operations: Subtract, Multiply and Divide: rations.Add rations. Subtract rations.Mult ations Divide inta a intar inta Add(int argo) e int perform(int arg1) Subtract(int arg0) int perform(int arg 1) Multiplytint argO) e int perform(int arg1) Divide(int argo) int The main conceptual jump here is how we can treat objects instantiated from different classes as the same at some level of abstraction - we don't want to have treat these four operations as completely unrelated in our code. The solution, as we've hinted at in lecture, is to introduce a new type (in this case it'l be an interface) which can service as a common supertype: CSE115 Lab 7 Spring 2016 ations. Bina erat o int orm(int arg) rations Add rations.Subtract rations.Mult rations. Divide inta Subtract(int argo) a int ar int ar Add(int argo) e int perform(int arg 1) Multiply(int argO) int perform(i Divide(int argo) e int perform(int arg 1 int performi int arg1) Once we've done this we can remember the currently selected operation in a variable of type operations. BinaryOperation.

Explanation / Answer

package part2.operations;
public class Add implements BinaryOperation {
   private int arg0;
  
   public Add(int arg0){
       this.arg0 = arg0;
   }
    @Override
    public int perform(int arg) {
        return this.arg0 + arg;
    }

}

package part2.operations;
public class Subtract implements BinaryOperation {
   private int arg0;
  
   public Subtract(int arg0){
       this.arg0 = arg0;
   }
    @Override
    public int perform(int arg) {
        return this.arg0 - arg;
    }

}

package part2.operations;
public class Multiply implements BinaryOperation {
   private int arg0;
  
   public Multiply(int arg0){
       this.arg0 = arg0;
   }
    @Override
    public int perform(int arg) {
        return this.arg0 * arg;
    }

}

package part2.operations;
public class Divide implements BinaryOperation {
   private int arg0;
  
   public Divide(int arg0){
       this.arg0 = arg0;
   }
    @Override
    public int perform(int arg) {
        return this.arg0 / arg;
    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote