D W

D W

  • NA
  • 12
  • 21.1k

Need a program to alphabetize a list of last names

Oct 25 2012 12:16 AM



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.

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

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



Answers (1)