Calculator - Individual
Update the existing calculator to make it more robust. For these additions, use the existing methods as a reference. The new methods will generally be very similar to the ones from the code-along activity.
Multiplication
Add the option to multiply the two integers the user provides.
Define the Method
Start with the method signature:
- Visibility:
public - Modifier:
static - Return type:
int - Name:
MultiplyNumbers - Parameters:
int integer1,int integer2
In the body of the method:
- Multiply the two
ints together - Return the result
Call the Method
- Check if the user would like to multiply numbers
- Use an
else ifunderneath the existing checks for addition and subtraction
- Use an
- If they want to multiply, call the
MultiplyNumbersmethod and store the result in a new variable- The parameters for the
MultiplyNumberscall should be the input from the user (aandb)
- The parameters for the
- Print the product to the console
Division
Add the option to divide the two integers the user provides. Follow the steps for multiplication, but name the method DivideNumbers, and use division instead of multiplication.
CHALLENGE: Quadratic Formula
- Allow the user to enter an additional number (
c) - Define a method that takes three inputs (
a,b, andc), and returns one of the results of the quadratic formula: https://www.purplemath.com/modules/quadform.htm#distform - If the user enters
"quadratic"for the operation they would like to perform, call the quadratic formula method on the inputs - Print the result to the console in the form
"x = {answer}"
EXTRA CHALLENGE:
Learn about C#
outparameters: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier
Use an out parameter so that the program can return both results of the quadratic formula, and print both to the console.