public override bool Equals(object obj)
        {
            Automobile temp = (Automobile)obj;

            if (this.IdNumber == temp.IdNumber)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Automobile[] automobiles = new Automobile[8];
            double       grandTotal  = 0;
            bool         goodNumber;

            for (int i = 0; i < automobiles.Length; i++)
            {
                automobiles[i] = new Automobile();
                Write("Enter automobile ID number >> ");
                automobiles[i].IdNumber = int.Parse(ReadLine());
                goodNumber = true;
                for (int j = 0; j < i; j++)
                {
                    if (automobiles[i].Equals(automobiles[j]))
                    {
                        goodNumber = false;
                    }
                }
                while (!goodNumber)
                {
                    Write("Sorry, the ID number " + automobiles[i].IdNumber + " is a duplicate. " + "\nPlease reenter >> ");
                    automobiles[i].IdNumber = int.Parse(ReadLine());
                    goodNumber = true;
                    for (int j = 0; j < i; j++)
                    {
                        if (automobiles[i].Equals(automobiles[j]))
                        {
                            goodNumber = false;
                        }
                    }
                }
                Write("Enter make >> ");
                automobiles[i].Make = ReadLine();
                Write("Enter year >> ");
                automobiles[i].Year = int.Parse(ReadLine());
                Write("Enter price >> ");
                automobiles[i].Price = double.Parse(ReadLine());
            }
            WriteLine("\n\t\t\tSUMARY");
            for (int i = 0; i < automobiles.Length; i++)
            {
                WriteLine(automobiles[i].ToString());
                grandTotal += automobiles[i].Price;
            }
            WriteLine("Total for all Automobile is >> " + grandTotal.ToString("c"));
        }
        int IComparable.CompareTo(object obj)
        {
            Automobile temp = (Automobile)obj;

            if (this.IdNumber > temp.IdNumber)
            {
                return(1);
            }
            else
            if (this.IdNumber < temp.IdNumber)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }