Okay so, I've written this code and gone over it many times to see if I can find my error. Unfortunately, I cannot find it and am becoming frustrated with myself. I've decided to post my code online. This is the actual Calculator class with the methods. The input class (not on this post) gets a user input and returns it as a string. Can someone please help me? Thanks bros.
public class Calculate extends UserInput{
int num1;
int num2;
int returnValue;
String operation;
String userInput1;
String userInput2;
public void calculate() {
userInput1 = getUserInput("Enter a number: ");
num1 = Integer.parseInt(userInput1); //Changing userInput to int
operation = getUserInput("Enter an operation (+,-,*, or /): ");
userInput2 = getUserInput("Enter a second number: "); //Changing second userInput to int
num2 = Integer.parseInt(userInput2);
if(operation == "+") {
addition(num1, num2);
} else if (operation == "-") {
subtraction(num1, num2);
} else if (operation == "*") {
multiplication(num1, num2);
} else if (operation == "/") {
division(num1, num2);
}
System.out.println("Result: " + returnValue);
}
public double addition(int x, int y) {
returnValue = x + y;
return returnValue;
}
public double subtraction(int x, int y) {
returnValue = x - y;
return returnValue;
}
public double multiplication(int x, int y) {
returnValue = x * y;
return returnValue;
}
public double division(int x, int y) {
returnValue = x / y;
return returnValue;
}
}