Question: In this activity, you will be able to create a basic calculator that includes all the basic math function such as adding, subtracting, etc. In
In this activity, you will be able to create a basic calculator that includes all the basic math function such as adding, subtracting, etc. In order to make the calculator, you will need to make a new method for each specific task (such as having an addition method).
First, write four basic methods:1. Below the main method, define the first method; this one will be for addition. First, create the method header:
What will you put as the method name? Make sure it clearly expresses what this method will do.
This method will be adding two numbers together and returning the sum knowing this, what will you make the return value type?
What should be included in the parameter list?
Next, write the method body. It should add the two parameters togetherand return the sum. What will the return statement look like? Keep it simple and dont include any output or input statements quite yet these will be done back in the main method.
Now do the same thing for the next three methods: subtraction, multiplication, and division.After this, add three additional methods of your choice. What other operations could a calculator do? Again, follow the same steps above in order to create these new methods.
For each of the seven operations above, the corresponding static method should be in the class file. Pay attention to curly braces.
Now we need to implement these methods back in the main method:
Create a menu to allow the user to choose from the 7 options, and allows them to keep choosing after each one, until they decide to quit. What kind of loop could you use for this? Will you decide to use a switch statement or if else statement?
For each option, include proper input and output, and then call themethod. Since each method returns a value, will you have that value saved in a variable to display, or have the returned value itself displayed? Dont forget to send in the correct values in the parameter
(you can use variables as well, instead of just fixed values).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
