What about math?

Report a typo

Write the class Fraction, which has two public fields: numerator and divisor. The constructor of the class should accept a numerator and divisor, so that fraction 1/2 can be created like this:

val half: Fraction = Fraction(1, 2)
println(half.numerator) // 1
println(half.divisor) // 2

Also, implement the sum of two fractions method to make the following code work:

val quarter = Fraction(1, 4)

quarter.summation(half) // Fraction(6, 8)

Fractions may not be abbreviated.

Sample Input 1:

Fraction(1, 2)
Fraction(2, 5)

Sample Output 1:

Fraction(9, 10)
Write a program in Scala 3
class Fraction
___

Create a free account to access the full topic