예제 #1
0
        //Compares this and another Odometer object.
        //Returns true if their miles and fuels are equivalents.
        public override bool Equals(object obj)
        {
            if (null == obj || GetType() != obj.GetType())
            {
                return(false);
            }
            Odometer other = (Odometer)obj;

            return(miles == other.miles && fuel == other.fuel);
        }
예제 #2
0
        static void Main(string[] args)
        {
            //Create first odometer: default constructor
            Console.WriteLine("Testing Odometer#1: Default Constructor....");
            Odometer odo = new Odometer();

            //Test Setters and getters
            Console.WriteLine("Odometer#1: SetMiles(95), SetFuel(4)....");
            odo.SetMiles(95);
            odo.SetFuel(4);
            Console.WriteLine("Odometer#1: GetMiles(): {0}, GetFuel(): {1}", odo.GetMiles(), odo.GetFuel());
            Console.WriteLine("Odometer#1: SetMiles(-35), SetFuel(-2)...");
            //Test negative invalid values and print Getters

            odo.SetMiles(-35);
            odo.SetFuel(-2);
            Console.WriteLine("Odometer#1: GetMiles(): {0}, GetFuel(): {1}", odo.GetMiles(), odo.GetFuel());

            //Test GetMPG()
            Console.WriteLine("Odometer#1: GetMPG(): {0}, ", odo.GetMPG());

            //Test Reset and print Getters
            Console.WriteLine("Odometer#1: Reset()");
            odo.Reset();
            Console.WriteLine("Odometer#1: GetMiles(): {0}, GetFuel(): {1}", odo.GetMiles(), odo.GetFuel());
            Console.WriteLine("Odometer#1: Add(120, 3)");

            //Test Add and print ToString
            odo.Add(120, 3);
            Console.WriteLine("Odometer#1: ToString(): {0}", odo);

            //Create a second odometer with full constructor
            Console.WriteLine("\n\nTesting Odometer#2: Full Constructor(120, 3)");
            Odometer odo2 = new Odometer(120, 3);

            //Test Equal Method
            Console.WriteLine("Test odo1.Equal(odo2): {0}", odo.Equals(odo2));

            //Test Add
            Console.WriteLine("Odometer#2: Add(30, 1)...");
            odo2.Add(30, 1);

            //Test ToString
            Console.WriteLine("Odometer#1: ToString(): {0}", odo);
            Console.WriteLine("Odometer#2: ToString(): {0}", odo2);
            Console.WriteLine("Test odo1.Equal(odo2): {0}", odo.Equals(odo2));

            //Print end of the test
            Console.WriteLine("End of the Test.....");

            Console.ReadLine();
        }
예제 #3
0
        static void Main(string[] args)
        {
            Odometer od1 = new Odometer();

            Console.WriteLine("Please enter the miles and press enter and then the fuel used and press enter.");
            Odometer od2 = new Odometer(Int32.Parse(Console.ReadLine()), Int32.Parse(Console.ReadLine()));

            Console.WriteLine(od2.ToString());

            od1.Add(32, 10);
            Console.WriteLine("other odometer: {0}", od1.ToString());
            od1.Reset();

            Console.WriteLine("Please enter the miles you would like to add and press enter. Then do the same for fuel used.");
            od2.Add(Int32.Parse(Console.ReadLine()), Int32.Parse(Console.ReadLine()));
            Console.WriteLine(od2.ToString());

            Console.WriteLine("other odometer after resetting: {0}", od1.ToString());

            Console.ReadLine();
        }