static void Main(string[] args)
        {
            Random   random   = new Random();
            Fraction fraction = new Fraction();

            for (int i = 0; i < 20; i++)
            {
                fraction.setFraction(random.Next(1, 100), random.Next(1, 100));

                string gcd      = fraction.getGCD().ToString();
                string reduced  = fraction.getReducedToLowestTerm();
                string asDouble = fraction.getAsDoubleValue().ToString();

                Console.WriteLine("ToString: {0, -5}  GCD(): {1, -4}  Reduced: {2, -8}  Double: {3}", fraction, gcd, reduced, asDouble);
            }

            Console.ReadLine();
        }
Exemple #2
0
        //Compares this fraction with another fraction.
        //Returns true if the decimal values are equals; false otherwise.
        public override bool Equals(object obj)
        {
            Fraction other = (Fraction)obj;

            return(getAsDoubleValue() == other.getAsDoubleValue());
        }