Пример #1
0
        /**
         * @param obj the object to check this against for equality
         * @return true if the given obj is a SimplifiedRational value and its
         * numerator and denominator are equal to this rational value's numerator and denominator,
         * false otherwise
         */
        public override bool Equals(object obj)
        {
            if (obj is SimplifiedRational)
            {
                SimplifiedRational s = (SimplifiedRational)obj;
                if (s.Numerator == this.Numerator && s.Denominator == this.Denominator)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        /**
         * Specialized constructor to take advantage of shared code between
         * Rational and SimplifiedRational
         * <p>
         * Essentially, this method allows us to implement most of RationalBase methods
         * directly in the interface while preserving the underlying type
         *
         * @param numerator
         *            the numerator of the rational value to construct
         * @param denominator
         *            the denominator of the rational value to construct
         * @return the constructed rational value
         * @throws ArgumentException
         *             if the given denominator is 0
         */
        public override RationalBase Construct(int numerator, int denominator)
        {
            if (denominator == 0)
            {
                throw new ArgumentException();
            }

            int[] array = new int[2];
            array = Simplify(numerator, denominator);
            SimplifiedRational returnObj = new SimplifiedRational(array[0], array[1]);

            return(returnObj);
        }
        /**
         * @param obj the object to check this against for equality
         * @return true if the given obj is a SimplifiedRational value and its
         * numerator and denominator are equal to this rational value's numerator and denominator,
         * false otherwise
         */
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            if (obj == null)
            {
                return(false);
            }

            SimplifiedRational check = null;

            if (obj is SimplifiedRational)
            {
                check = (SimplifiedRational)obj;
            }

            return(check.Numerator == Numerator && check.Denominator == Denominator);
        }
Пример #4
0
        /**
         * @param obj the object to check this against for equality
         * @return true if the given obj is a SimplifiedRational value and its
         * numerator and denominator are equal to this rational value's numerator and denominator,
         * false otherwise
         */
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }

            SimplifiedRational t = null;

            if (obj is SimplifiedRational)
            {
                t = (SimplifiedRational)obj;
            }
            else
            {
                return(false);
            }
            return(this.Numerator == t.Numerator && this.Denominator == t.Denominator);
        }