Guest User

Untitled

a guest
May 31st, 2013
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import javax.swing.JOptionPane;
  4.  
  5. public class Sorter
  6. {
  7.     public static void main(String[] args)
  8.     {
  9.         Scanner keyboard = new Scanner(System.in);
  10.         ArrayList<String> wordList = new ArrayList<String>();
  11.        
  12.         int choice = 1;
  13.         while(choice > 0)
  14.         {
  15.             System.out.println("What would you like to do?");
  16.             System.out.println("1) Enter a new list of Words.");
  17.             System.out.println("2) Display the last entered list of words in alphabetical order.");
  18.             System.out.println("3) Show the current list of words.");
  19.             System.out.println("0) End the program. ");
  20.             System.out.print("> ");
  21.             choice = Integer.parseInt(keyboard.nextLine());
  22.             if(choice < 0 || choice > 3)
  23.             {
  24.                 System.out.print("Invalid Choice!");
  25.                 continue;
  26.             }
  27.             else if(choice == 1)
  28.             {
  29.                 getArrayList(wordList);
  30.             }
  31.             else if(choice == 2)
  32.             {
  33.                
  34.             }
  35.             else if(choice == 3)
  36.             {
  37.                 displayList(wordList);
  38.             }
  39.         }
  40.         System.out.print("Goodbye!");
  41.     }
  42.     public static void getArrayList(ArrayList<String> wordList)
  43.     {
  44.         @SuppressWarnings("resource")
  45.         Scanner input = new Scanner(System.in);
  46.         System.out.println("Enter in a list of words. Enter the word 'Return' to return to the menu.");
  47.         System.out.print("> ");
  48.         String addToList = input.nextLine();
  49.         String exit = "Return";
  50.         while(!addToList.equalsIgnoreCase(exit))
  51.         {
  52.             System.out.print("> ");
  53.             wordList.add(input.nextLine());
  54.         }
  55.     }
  56.     public static void displayList(ArrayList<String> wordList)
  57.     {
  58.         for(String printer : wordList)
  59.         {
  60.             System.out.println(printer);
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment