Question: We would like you to implement the methods in the class Rational that is supposed to represent fractionswhere the numerator and denominator are integers n,



We would like you to implement the methods in the class Rational that is supposed to represent fractionswhere the numerator and denominator are integers n, d. Note that it is important to ensure that d f 0 Implement the missing methods below You should read this blog post about how to convert between numeric types https://alvinalexande meric-types- in-scala-int-long-float-double ow- class Rational(val n: Int, val d: Int) //Implement a pretty printer override def toString(): String = { s"$n/$d" def isValid(): Boolean { var ret = true retfalse return ret def toDouble(): Double val dn n.toDouble val dd d.toDouble return dn/dd
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
