Beispiel #1
0
        static void Main(string[] args)
        {
            MutableRational mute = new MutableRational(1, 1);

            Console.Out.WriteLine(mute.toString());
            ImmutableRational immute = new ImmutableRational(1, 1);

            Console.Out.WriteLine(immute.toString());
        }
Beispiel #2
0
        public void add(int value)
        {
            MutableRational rational = new MutableRational(value);

            int LCM = leastCommonMultiple(denominator, rational.denominator);

            denominator = LCM;
            numerator   = (numerator * (LCM / denominator)) + (rational.numerator * (LCM / rational.denominator));
            reduce();
        }
Beispiel #3
0
        public void multiply(int value)
        {
            //create a new rational when passed a value
            MutableRational rational = new MutableRational(value);

            //implement logic for the multiply function concernning type  rational
            numerator   *= rational.numerator;
            denominator *= rational.denominator;
            reduce();
        }
Beispiel #4
0
        public bool AreEqual(Object obj)
        {
            MutableRational rValue = (MutableRational)obj;
            bool            result = false;

            if (rValue.numerator == numerator && rValue.denominator == denominator)
            {
                result = true;
            }
            return(result);
        }
Beispiel #5
0
        public void subtraction(MutableRational rational)
        {
            int LCM          = leastCommonMultiple(denominator, rational.denominator);
            int LCMDivision  = LCM / denominator;
            int temp1        = numerator * LCMDivision;
            int LCMDivision2 = LCM / rational.denominator;
            int temp2        = rational.numerator * LCMDivision2;

            numerator   = temp1 - temp2;
            denominator = LCM;
            reduce();
        }
Beispiel #6
0
        public void divide(MutableRational rational)
        {
            //we need to check to see if the denominator is a valid value
            //IE not Zero

            if (rational.denominator == 0)
            {
                throw new Exception("IllegalArgument");
            }
            denominator = denominator * rational.numerator;
            numerator   = numerator * rational.denominator;
            reduce();
        }
Beispiel #7
0
        public void divide(int value)
        {
            //create a new Rational
            MutableRational rational = new MutableRational(value);

            //check to see if denominator is valid
            if (rational.denominator == 0)
            {
                throw new Exception("IllegalArgument");
            }
            denominator = denominator * rational.numerator;
            numerator   = numerator * rational.denominator;
            reduce();
        }
Beispiel #8
0
 public void multiply(MutableRational rational)
 {
     numerator   *= rational.numerator;
     denominator *= rational.denominator;
     reduce();
 }