예제 #1
0
 static void Main(string[] args)
 {
     TaxPayer[] user = new TaxPayer[4];
     for (int counter = 0; counter < 4; ++counter)
     {
         user[counter] = new TaxPayer();
         Console.Write("Enter Social Security Number for taxpayer " + (counter + 1) + " ");
         user[counter].SocialSecurity = Console.ReadLine();
         Console.Write("Enter Gross income for taxpayer " + (counter + 1) + " ");
         user[counter].GrossIncome = Convert.ToDouble(Console.ReadLine());
     }
     for (int counter = 0; counter < 4; ++counter)
     {
         Console.WriteLine("Taxpayer #" + (counter + 1) + " SSN: " + user[counter].SocialSecurity
                           + " income " + user[counter].GrossIncome.ToString("C2")
                           + " Tax is " + user[counter].IncomeTax.ToString("C2"));
     }
     Console.WriteLine("\n-------------------------------------------------------");
     Array.Sort(user);
     for (int counter = 0; counter < 4; ++counter)
     {
         Console.WriteLine("Taxpayer #" + (counter + 1) + " SSN: " + user[counter].SocialSecurity
                           + " income " + user[counter].GrossIncome.ToString("C2")
                           + " Tax is " + user[counter].IncomeTax.ToString("C2"));
     }
     Console.ReadLine();
 }
예제 #2
0
        int IComparable.CompareTo(Object o)
        {
            int      returnVal;
            TaxPayer temp = (TaxPayer)o;

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