Working on an assignment for school, cant figure out what i need to do to move on in this project...
We are suppose to implement these exact methods into my calculator program.
public static int getMenuOption() public static double getOperand(String prompt) public static double add (double operand1, double operand2) public static double subtract (double operand1, double operand2) public static double multiply(double operand1, double operand2) public static double divide(double operand1, double operand2) public static double random(double operand1, double operand2)
Now my issue is that i cant seem to figure out how to get the get menu option to choose the static double, maybe im not fully understanding the question that is being asked by my teacher, but he seems hard to get ahold of.
here is my current code...
import java.util.Scanner; public class CaluclatorWithMethods { public static void main(String[] args) { System.out.println(" Menu: "); System.out.println("1. Add "); System.out.println("2. Sub "); System.out.println("3. Multiply "); System.out.println("4. Divide "); System.out.println("5. Generate a Random Number"); Scanner input = new Scanner(System.in); System.out.println(" What would you like to do?"); int getMenuOption = input.nextInt(); } public static int getMenuOption( int 1, int 2, int 3, int 4, int 5){ if (getMenuOption == 1 ) { return add(); } if (getMenuOption == 2) { return subtract(); } if (getMenuOption == 3 ) { return multiply(); } if (getMenuOption == 4 ) { return divide(); } if (getMenuOption == 5 ) { return random(); } } public static double getOperand(String prompt) { Scanner input = new Scanner(System.in); double operand1 = getOperand("What is the First number? "); operand1 = input.nextDouble(); double operand2 = getOperand("What is the Second number? "); operand2 = input.nextDouble(); return operand1; } public static double add(double operand1, double operand2) { getOperand(null); double answer = operand1 + operand2; return answer; } public static double subtract(double operand1, double operand2) { getOperand(null); double answer = operand1 - operand2; return answer; } public static double multiply(double operand1, double operand2) { getOperand(null); double answer = operand1 * operand2; return answer; } public static double divide(double operand1, double operand2) { getOperand(null); double answer = operand1 / operand2; return answer; } public static double random(double lowerLimit, double upperLimit) { Scanner input = new Scanner(System.in); double operand1 = getOperand("What is the Lower Limit? "); operand1 = input.nextDouble(); double operand2 = getOperand("What is the Upper Limit? "); operand2 = input.nextDouble(); double answer = (double) (Math.ceil(Math.random() * (upperLimit - lowerLimit)) + lowerLimit); return answer; } }
My instructions state this "
In the case of subtraction, you would want to do something like this :
double operand1 = getOperand("What is the First number? ");
double operand2 = getOperand("What is the Second number? ");
// call your subtract method and pass it these inputs
"
Any help would be grateful!