Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your mission: Write a program to alphabetize a list of last names. The user will

ID: 3647507 • Letter: Y

Question

Your mission: Write a program to alphabetize a list of last names. The user will input an undetermined number of last names. The program will display the number of names entered and alphabetized lists of the names in ascending (A-Z) and descending (Z-A) order.

Your program will store the names in an ArrayList object. It will use various ArrayList properties and methods to implement the program requirements.

Sample output:

Enter a last name: Roberts
Keep going? (Y/N): y
Enter a last name: DeLay
Keep going? (Y/N): y
Enter a last name: Foreman
Keep going? (Y/N): y
Enter a last name: Ganguly
Keep going? (Y/N): n

4 last names entered

Names in Ascending Order

DeLay
Foreman
Ganguly

Names in Descending Order

Roberts
Ganguly
Foreman
DeLay

Explanation / Answer

Dear, Here is the C# programming code for your assignment... class Alphabetize { //Main method static void Main(string[] args) { //declaring array list object ArrayList lastNames=new ArrayList(); //string variable for storing user choice to continue string choice; //for reading name string lastName; //loop for reading in-definite number of names do { //prompting user to enter name Console.Write("Enter a last name : "); //reading name lastName=Console.ReadLine(); //adding name to array list lastNames.Add(lastName); //asling user to continue Console.Write("Keep going? (Y/N):"); //reading user choice choice = Console.ReadLine(); choice = choice.ToLower(); //verifying loop condition then do next }while(choice.Substring(0,1).Equals("y")); //Displaying how many number of names read Console.WriteLine("{0} last name(s) entered.", lastNames.Count); //displaying names in ascending order Console.WriteLine("Names in Ascending Order :"); lastNames.Sort();//calling sort method of array list //calling static method to displaying names show(lastNames); //displaying names in descending order Console.WriteLine("Names in Descending Order :"); //calling reverse method of array list lastNames.Reverse(); //calling static method to displaying names show(lastNames); Console.Read();//waiting for user response }//end of main //user defined method to show names public static void show(ArrayList al) { foreach (string ele in al) { Console.WriteLine(ele); } }//end of method }//end of class