static void Main(string[] args) { Taxpayer[] people = new Taxpayer[5]; string ssn; double grossIncome = 0; //instantiate an array of 5 taxpayer objects for (int i = 0; i < people.Length; i++) { people[i] = new Taxpayer(); } /* implement a for loop that will prompt the user to enter the * social security number and gross income*/ for (int i = 0; i < people.Length; i++) { ssn = Input.promptString("Enter Social Security Number for taxpayer " + (i + 1) + ": ", "Please enter something into the prompt... "); grossIncome = Input.promptDouble("Enter gross income for taxpayer " + (i + 1) + ": ", "Please enter a valid currency value... "); people[i].SSN = ssn; //are we supposed to call Taxpayer.getRates() here? people[i].YearlyGross = grossIncome; Console.WriteLine(); } //implement a for loop that will display each object as a formatted taxpayer SSN, income, and calculated tax for (int i = 0; i < people.Length; i++) { Console.WriteLine(string.Format("Taxpayer # {0} SSN: {1} income: {2:C} Tax is: {3:C}", (i + 1), people[i].SSN, people[i].YearlyGross, people[i].TaxOwed)); } Console.WriteLine(); //implement a for loop that will sort the five objects in order by the amount of tax owed and then display each object as formatted taxpayer SSN, income, and calculated tax Array.Sort(people); for (int i = 0; i < people.Length; i++) { Console.WriteLine(string.Format("Taxpayer # {0} SSN: {1} income: {2:C} Tax is: {3:C}", (i + 1), people[i].SSN, people[i].YearlyGross, people[i].TaxOwed)); } pause(); }//end main
//implement the CompareTo method mandated by IComparable public int CompareTo(object obj) { if (obj == null) { return(1); } Taxpayer other = obj as Taxpayer; if (other != null) { return(this.taxOwed.CompareTo(other.taxOwed)); } else { throw new ArgumentException("Object is not a TaxPayer"); } }
static void Main(string[] args) { Taxpayer[] people = new Taxpayer[5]; string ssn; double grossIncome = 0; //instantiate an array of 5 taxpayer objects for (int i = 0; i < people.Length; i++) people[i] = new Taxpayer(); /* implement a for loop that will prompt the user to enter the * social security number and gross income*/ for (int i = 0; i < people.Length; i++) { ssn = Input.promptString("Enter Social Security Number for taxpayer " + (i + 1) + ": ", "Please enter something into the prompt... "); grossIncome = Input.promptDouble("Enter gross income for taxpayer " + (i + 1) + ": ", "Please enter a valid currency value... "); people[i].SSN = ssn; //are we supposed to call Taxpayer.getRates() here? people[i].YearlyGross = grossIncome; Console.WriteLine(); } //implement a for loop that will display each object as a formatted taxpayer SSN, income, and calculated tax for (int i = 0; i < people.Length; i++) Console.WriteLine(string.Format("Taxpayer # {0} SSN: {1} income: {2:C} Tax is: {3:C}", (i + 1), people[i].SSN, people[i].YearlyGross, people[i].TaxOwed)); Console.WriteLine(); //implement a for loop that will sort the five objects in order by the amount of tax owed and then display each object as formatted taxpayer SSN, income, and calculated tax Array.Sort(people); for (int i = 0; i < people.Length; i++) Console.WriteLine(string.Format("Taxpayer # {0} SSN: {1} income: {2:C} Tax is: {3:C}", (i + 1), people[i].SSN, people[i].YearlyGross, people[i].TaxOwed)); pause(); }