Class RationalNumber

java.lang.Object
it.unimi.di.prog2.e10.RationalNumber

public class RationalNumber extends Object
A rational number is an immutable number that can be expressed as the quotient or fraction \( p/q \) of two ints, a numerator \( p \) and a non-zero denominator \( q \).
  • Constructor Details

    • RationalNumber

      public RationalNumber(int numerator, int denominator)
      Creates a new rational number.
      Parameters:
      numerator - the numerator.
      denominator - the denominator.
  • Method Details

    • add

      public RationalNumber add(RationalNumber other)
      Returns the sum of this rational number and another one.
      Parameters:
      other - the other rational number.
      Returns:
      the sum of this rational number and other.
    • mul

      public RationalNumber mul(RationalNumber other)
      Returns the product of this rational number and another one.
      Parameters:
      other - the other rational number.
      Returns:
      the product of this rational number and other.