I'm currently coding a clock app in java for android, and I want to implement a snooze function where when the alarm goes off, a random math problem would appear on the screen. The user would have to successfully answer the math problem before the alarm would snooze/turn off. I'm completely lost on how I would implement this feature. Any guidance on how i'd implement this would be greatly appreciated. Thanks.
-
2Please see: [Why is βCan someone help me?β not an actual question?](http://meta.stackoverflow.com/q/284236) β takendarkk Mar 22 '18 at 19:52
-
You can choose randomly from the operations + - / *. And then depending on the operation again get some random numbers preferably from some range. For Math.random() refer https://stackoverflow.com/questions/7961788/math-random-explained β Karan Khanna Mar 22 '18 at 20:09
1 Answers
First, I'd like to say that what ever I'm about to tell you is the way I would do it, since you did not specify any way specifically you would like to do it. I am no Java expert, but you could probably generate two random integers from a certain range (maybe something like 2 to 11) using Math.random
. Try looking at this question for info on how to do that: How do I generate random integers within a specific range in Java? or Math.random() explained Then maybe generate a random number from 1 to 4 where 1 is addition, 2 is subtraction, 3 is multiplication, and 4 is addition. Then you could have an if statement for subtraction and division that checks if the first number is greater than the second number. Also, you could have another if statement for division checking if the division statement ends up with a whole number. Then you could have a final if statement checking if the user typed in the right answer. If you want you could make little alerts for if they got it wrong or right. As for the snooze function, you could just make a property that adds a certain amount of minutes to your method for the alarm. Also, I'd like to say that I like your idea for the math problems!