Question
You will create a Java class in BlueJ called Calculator. The Calculator class will have the following: An integer field called operand1. A second integer
You will create a Java class in BlueJ called Calculator.
The Calculator class will have the following:
An integer field called operand1. A second integer field called operand2. A constructor that takes no operands and initializes both fields to zero. A method setOperands that takes two integer parameters op1 and op2 and sets the values of operand1 to op1 and operand2 to op2. A method add that takes a single parameter called answer. The method then checks the answer provided against the sum of operand1 and operand2 and outputs a corresponding message. For example, if the current values of operand1 and operand2 are 3 and 6 respectively and the value of answer provided is 9 the message might look like this: 3 + 6 = 9 You are correct! If the answer provided does not match the actual sum the message might be: 3 + 6 = 9 You need more practice! A method subtract that is similar to add but for subtraction. A method multiply that is similar to add but for multiplication. A method divide that takes two parameters quotient and remainder. This method is similar to add but you must check both the quotient and remainder of the operation operand1 / operand2. In addition, you should check operand2 to prevent the possibility of division by zero.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started