Programming, Scala, Data Type, Abstraction, Introduction.
numerator :Int = x / gcd(x, y) def denominator :Int = y / gcd(x, y) // ... } This variation uses the calculation directly when creating the numerator and denominator. If there will be no need to use the gcd anywhere else you can keep this implementation. class Rational(x: Int, y:Int) { private def