Class Fraction


  • public class Fraction
    extends java.lang.Object
    Implements the concept of fractions
    Author:
    Stephan Preibisch
    • Constructor Summary

      Constructors 
      Constructor Description
      Fraction()
      Instantiate a Fraction with a value of 1
      Fraction​(long numerator, long denominator)
      Creates a new fraction with the respective values
    • Constructor Detail

      • Fraction

        public Fraction​(long numerator,
                        long denominator)
        Creates a new fraction with the respective values
        Parameters:
        numerator - (above fraction bar)
        denominator - (below fraction bar)
      • Fraction

        public Fraction()
        Instantiate a Fraction with a value of 1
    • Method Detail

      • getNumerator

        public long getNumerator()
        Returns:
        - the numerator (above the fraction bar)
      • getDenominator

        public long getDenominator()
        Returns:
        - the denominator (below the fraction bar)
      • getRatio

        public double getRatio()
        Returns:
        - an estimate of the ratio in double, i.e. numerator/denominator
      • invert

        public void invert()
        Inverts this fraction by exchanging numerator and denominator
      • mul

        public void mul​(Fraction fraction)
      • div

        public void div​(Fraction fraction)
      • mulCeil

        public long mulCeil​(long value)
        Multiply the value with this fraction. Return the ceiled value (e.g. 10.2 = 11) if the result is a fraction.
        Parameters:
        value -
        Returns:
      • clone

        public Fraction clone()
        Overrides:
        clone in class java.lang.Object