All pastes #676508 Raw Edit

Someone

public text v1 · immutable
#676508 ·published 2007-08-31 03:36 UTC
rendered paste body
    class Fraction
    {
        int top;
        int bottom;
        public Fraction(int top, int bottom)
        {
            this.top = top;
            this.bottom = bottom;
        }
        public Fraction Add(int newTop, int newBottom)
        {
            if (newBottom == this.bottom)
            {
                return Fraction((this.top + newTop), this.bottom);
            }
            Fraction tempFractionA = new Fraction((this.top * newBottom), (this.bottom * newBottom));
            Fraction tempFractionB = new Fraction((newTop * this.bottom), (newBottom * this.bottom));
            return tempFractionA.Add(tempFractionB);
        }
        public Fraction Add(Fraction newFraction)
        {
            this.Add(newFraction.top, newFraction.bottom);
        }
        public Fraction Add(int newTop)
        {
            this.Add(newTop, 1);
        }
        public Fraction Subtract(int newTop, int newBottom)
        {
            if (newBottom == this.bottom)
            {
                return Fraction((this.top - newTop), this.bottom);
            }
            Fraction tempFractionA = new Fraction((this.top * newBottom), (this.bottom * newBottom));
            Fraction tempFractionB = new Fraction((newTop * this.bottom), (newBottom * this.bottom));
            return tempFractionA.Subtract(tempFractionB);
        }
        public Fraction Subtract(Fraction newFraction)
        {
            this.Subtract(newFraction.top, newFraction.bottom);
        }
        public Fraction Subtract(int newTop)
        {
            this.Subtract(newTop, 1);
        }
        public Fraction Multiply(int newTop, int newBottom)
        {
            return Fraction((this.top * newTop), (this.bottom * newBottom));
        }
        public Fraction Multiply(Fraction newFrac)
        {
            return this.Multiply(newFrac.top, newFrac.bottom);
        }
        public Fraction Multiply(int newTop)
        {
            return this.Multiply(newTop, 1);
        }
        public Fraction Divide(int newTop, int newBottom)
        {
            return Fraction((this.top * newBottom), (this.bottom * newTop));
        }
        public Fraction Divide(Fraction newFrac)
        {
            return this.Divide(newFrac.top, newFrac.bottom);
        }
        public Fraction Divide(int newTop)
        {
            return this.Divide(newTop, 1);
        }
    }