Guest User

Untitled

a guest
May 31st, 2013
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package ProjectFoo;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class ProjectFoo
  7. {
  8.     public static void main(String[] args) throws Exception
  9.     {
  10.         ArrayList<String> wordList = new ArrayList<>();
  11.  
  12.         Scanner keyboard = new Scanner(System.in);
  13.  
  14.         int choice = 1;
  15.  
  16.         while(choice > 0)
  17.         {
  18.             System.out.println("What would you like to do?");
  19.             System.out.println("1) Enter a word into the list.");
  20.             System.out.println("2) Display a list of words in the current list.");
  21.             System.out.println("3) Print the current list of words in alphabetical order.");
  22.             System.out.println("0) Exit Program.");
  23.  
  24.             choice = Integer.parseInt(keyboard.nextLine());
  25.  
  26.             if(choice < 0 || choice > 3)
  27.             {
  28.                 System.out.print("Invalid Choice!");
  29.                 continue;
  30.             }
  31.             else if(choice == 1)
  32.             {
  33.                 createList(wordList);
  34.             }
  35.             else if(choice == 2)
  36.             {
  37.                 displayList(wordList);
  38.             }
  39.             else if(choice == 3)
  40.             {
  41.  
  42.             }
  43.         }
  44.  
  45.         System.out.print("Goodbye!");
  46.     }
  47.  
  48.     public static void createList(ArrayList<String> inWordList)
  49.     {
  50.         Scanner input = new Scanner(System.in);
  51.  
  52.         System.out.println("Type a word then press enter.");
  53.  
  54.         String addToList = input.nextLine();
  55.            
  56.         inWordList.add(addToList);
  57.     }
  58.  
  59.     public static void displayList(ArrayList<String> inWordList)
  60.     {
  61.         for(String s : inWordList)
  62.         {
  63.             System.out.println(s);
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment