I am trying to understand how exactly you are meant to prompt a user for two numbers and then list a menu for them to choose the course of action they want to do with those numbers however I am quite new to java and do not understand the concept very well. If someone could help me the specifics are below as well as the code that I have so far.
- Prompt the user for two integers.
Display a menu with the following options:
- Add numbers
- Subtract numbers
Prompt the user for a single integer that is either 1,2, or 3.
- If the user enters an invalid selection, redisplay the menu and prompt them again. Continue this until you get a valid response (1,2,or 3). You must use a loop to do this.
- If the user selects ‘3’ then exit the program.
- Perform the associated operation (add or subtract) on the previously entered two integers and display the result. Return to step ‘b’ and continue in this manner until the user selects ‘3’ to exit the program.
- Name the class CalcJava and save program as CalcJava.java
Submit the program using the WA3 link above.
public class CalcJava
public static void main(String args)
Scanner inputDevice = new Scanner(System.in);
System.out.print("Please enter a number:");
num1 = inputDevice.nextInt();
System.out.print("Please enter a second number: ");
num2 = inputDevice.nextInt();
System.out.println("Your numbers are: " + num1 + " and "+ num2);
I know that it is not much but this is the point that I have gotten to so far. If someone could point me in the right direction then it would be a big help.
Thank you in advance.