dimanche 28 octobre 2018

Method that generates two random numbers within a changeable range

So for part of my assignment I need to create a method of a random math generator in which you can practice addition, subtraction, multiplication, and division on.

I need to create a method in which the range is different based on what operation you are doing.. For example

1. Addition problems

  • Both operands should be random numbers in the range, 1 to 500, inclusive

2. Subtraction problems

  • Both operands should be random numbers in the range, 1 to 999, inclusive
  • But the second operand, (the number being subtracted from the top number) should be less than or equal to the first operand

3. Multiplication problems

  • The first operand (top number) must be in the range of 1 to 100, inclusive.
  • The second operand (bottom number) must be in the range of 1 to 9, inclusive.

4. Division problems

  • The range for the divisor (operand 2) must be from 1 to 9, inclusive
  • The dividend (operand 1) must have a value such that the resulting quotient is always in the range of 1 to 50, inclusive

Then after that, I would do an if else statement that looks similar to this:

correctAnswer = firstRandomNumber + secondRandomNumber
if (userInput = correctAnswer) 
{
system.out.println ("Correct!");
}
else 
{
system.out.println ("Wrong!");
}

How would I go on about doing this?




Aucun commentaire:

Enregistrer un commentaire