Class Fraction

    • Constructor Detail

      • Fraction

        public Fraction​(long numerator,
                        long denominator)
        Parameters:
        numerator - The fraction's numerator.
        denominator - The fraction's denominator.
    • Method Detail

      • getValue

        public double getValue()
        Returns:
        The fraction's decimal value e.g. 1/3 = 0.3333...
      • getNumerator

        public long getNumerator()
        Returns:
        The fraction's numerator
      • setNumerator

        public void setNumerator​(long numerator)
        Parameters:
        numerator - Set the fraction's numerator.
      • getDenominator

        public long getDenominator()
        Returns:
        The fraction's denominator value
      • setDenominator

        public void setDenominator​(long denominator)
        Parameters:
        denominator - Set the fraction's denominator
      • add

        public Fraction add​(Fraction f)
        Add a second fraction to the current instance.
        Parameters:
        f - A second fraction.
        Returns:
        The sum of the current instance and f according to: \[ {a\over b} + {x\over y} = {{ay + bx}\over by} \]
      • mult

        public Fraction mult​(Fraction f)
        Multiply a second fraction by this instance
        Parameters:
        f - Building the product with this second fraction.
        Returns:
        The result of multiplying the current instance by f according to: \[ {a\over b} \cdot {x\over y} = {{ax}\over by} \]