I'm taking an online java class and the teacher has asked for the following: Write a menu program that ask a user for a number indicating the four basic math equations(addition, subtraction, multiplication, division). Using a if/else structure to do the required operation, ask the user for inputs and solve the equation. I am new to this, but I don't see the point of the if/else, but I guess that is irrelavent.
If I use case 1, 2, 3, 4 as below to determine the operation, how do I refference the case with a 'If statement'?
int userSelection;
double x;
double y;
double answer;
switch ( userSelection ) {
case 1:
TextIO.putln("Let's add! ");
TextIO.putln();
TextIO.putln("Enter the first number: ");
x = TextIO.getlnDouble();
TextIO.putln("Enter the second number: ");
y = TextIO.getlnDouble();
break;
//I thought I could use the 'If' like this
if (case 1); // I don't know how to refference this correctly
answer = x + y;
TextIO.putln( x 'plus' y 'equals' answer);
Thanks in advance!