Untitled
unknown
plain_text
a year ago
637 B
6
Indexable
package com.example.alarmclock.utils
class MathProblem {
val question: String
private val answer: Int
init {
val num1 = (0..10).random()
val num2 = (0..10).random()
val operator = listOf("+", "-", "*", "/").random()
question = "$num1 $operator $num2 ="
answer = when (operator) {
"+" -> num1 + num2
"-" -> num1 - num2
"*" -> num1 * num2
"/" -> num1 / num2
else -> throw IllegalArgumentException("Invalid operator")
}
}
fun checkAnswer(answer: Int): Boolean {
return answer == this.answer
}
}Editor is loading...
Leave a Comment