Question
The editing window below includes a custom class called Calculator. Develop the Calculator class to calculate values in custom methods, using data received from the
The editing window below includes a custom class called "Calculator". Develop the Calculator class to calculate values in custom methods, using data received from the Main() method (which you also must develop).
- In Main(), declare three integer variables: firstNum, secondNum and output.
- Prompt the user with the text "Enter the first value:", and store that value in firstNum.
- Prompt the user with the text "Enter the second value:", and store that value in secondNum.
- Declare an instance of the Calculator class so it can be used as an object later in the program code.
- Make a custom method within the Calculator class (the lower one) called "Multiply", with two incoming integer parameters called "first" and "second").
- In the Multiply method, write code that will multiply the first incoming parameter ("first") times the second incoming parameter ("second") and return the result. (Tip: Create an integer variable called "total" within the method to store the result of the calculation, then send total back with the return command.)
- Make additional methods called "Add", "Subtract", and "Divide". Write code within each method to perform the relevant calculation (addition, subtraction, and division).
- The customer wants only the Multiplication result to be displayed at this time. (Note: The other three methods will be tested when you submit the project for grading.) From Main(), display the results of the multiplication command in the following way (exactly):
Result: 12
Test your program and ensure that each calculation produces the expected result.
Important Notes (READ CAREFULLY!):
- This program does not require either a loop or an IF statement.
- Only the shell of the custom class is provided, so you will need to write the entire methods, including the declaration lines. Be careful to name them according to the instructions (step 6). Any difference in the name will cause the grading algorithm to not see your method. (Tip: A review of the default code from the Unit 2 Lab Assignment may be helpful.)
import java.util.Scanner;
public class LabProgram { public static void main(String[] args) { /* Type code below this line. Make additional lines as needed. */ } // do not delete this line } // do not delete this line
class Calculator { /* Type code below this line. Make additional lines as needed. */
} // do not delete this line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Heres the completed code import javautilScanner public class LabProgram public static void mainStrin...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