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

I need help with the following assignment for my lab. I will copy and paste it f

ID: 3629503 • Letter: I

Question

I need help with the following assignment for my lab. I will copy and paste it for you so you will fully understand the problem. This will be in C# and utilize a tacky GUI with an messagebox.

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

Tips

Best practices: Don't try to write too much at a time! First, write an outline in comments based on the requirements and the pseudocode. Then, work on instantiating an ArrayList object, followed by implementing the loop that will get user input. As always, keep things simple and implement incrementally. Review the list of ArrayList methods and properties in the textbook and experiment with the ones you think you'll need.

Pseudocode

Main function
Instantiate ArrayList object
Loop to get last names, until user wants to quit
Add each last name to the ArrayList
Display the count of the last names
Sort the ArrayList
Loop to display the names
Reverse the order of the ArrayList
Loop to display the names

Explanation / Answer

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