Note that there are some explanatory texts on larger screens.

plurals
  1. POconvert string to arithmetic operation
    primarykey
    data
    text
    <p>I'm doing a program that presents the student with a math quiz. I am having trouble figuring out how to take the input problem type and turning that string into the arithmetic operator. Here is the method for that part of the code. Please and thanks!</p> <pre><code>public static String getUserChoice(String choice) { Scanner in = new Scanner(System.in); System.out.println("Please enter the symbol that corresponds to one of the following problems\n" + "Addition (+)\n Subtraction (-)\n or Multiplication (*): "); choice = in.next(); if ("+".equals(choice)){ return +; } } return choice; </code></pre> <p><strong>Update</strong> Here's the entire code if it helps see what I am doing.</p> <pre><code> public static void main(String[] args) { int digit = 0; int random = 0; String result1 = getUserChoice(""); digit = getNumberofDigit1(digit); int number1 = getRandomNumber1(digit); int number2 = getRandomNumber2(digit); System.out.println(number1 + result1 + number2); getCorrectAnswer(number1, result1, number2); } public static String getUserChoice(String choice) { Scanner in = new Scanner(System.in); System.out.println("Please enter the symbol that corresponds to one of the following problems\n" + "Addition (+)\n Subtraction (-)\n or Multiplication (*): "); choice = in.next(); return choice; } public static int getNumberofDigit1(int digit) { Scanner in = new Scanner(System.in); System.out.println("Enter a 1 for problems with one digit, or a 2 for two-digit problems: "); digit = in.nextInt(); return digit; } public static int getRandomNumber1(int numbers) { int random = 0; if (numbers == 1) { random = (int) (1 + Math.random() * 9); } else if (numbers == 2) { random = (int) (10 + Math.random() * 90); } return random; } public static int getRandomNumber2(int numbers) { int random2 = 0; if (numbers == 1) { random2 = (int) (1 + Math.random() * 9); } else if (numbers == 2) { random2 = (int) (10 + Math.random() * 90); } return random2; } public static void getCorrectAnswer(int number1, String result1, int number2) { } public static void getUserAnswer() { Scanner in = new Scanner(System.in); } public static void CheckandDisplayResult() { } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload