class Task3(
override val TAG: String,
private val generations: Int
) : HomeWorkSolution() {
override fun answer(): Double {
var num = 0
var div = 0
for (i in 0..generations) {
val a = Random.nextDouble(0.0, 1.0)
val b = Random.nextDouble(0.0, 1.0)
val c = Random.nextDouble(0.0, 1.0)
if (isEquation(a, b)) {
if (isSolutionInRealNumbers(a, b, c)) num++
div++
}
}
return num.toDouble() / div
}
private fun isSolutionInRealNumbers(a: Double, b: Double, c: Double) = b * b - 4 * a * c >= 0
private fun isEquation(a: Double, b: Double) = a != 0.0 || b != 0.0
}
What error are you getting? What is answer()
overriding?