Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ProjectFoo;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class ProjectFoo
- {
- public static void main(String[] args) throws Exception
- {
- ArrayList<String> wordList = new ArrayList<>();
- Scanner keyboard = new Scanner(System.in);
- int choice = 1;
- while(choice > 0)
- {
- System.out.println("What would you like to do?");
- System.out.println("1) Enter a word into the list.");
- System.out.println("2) Display a list of words in the current list.");
- System.out.println("3) Print the current list of words in alphabetical order.");
- System.out.println("0) Exit Program.");
- choice = Integer.parseInt(keyboard.nextLine());
- if(choice < 0 || choice > 3)
- {
- System.out.print("Invalid Choice!");
- continue;
- }
- else if(choice == 1)
- {
- createList(wordList);
- }
- else if(choice == 2)
- {
- displayList(wordList);
- }
- else if(choice == 3)
- {
- }
- }
- System.out.print("Goodbye!");
- }
- public static void createList(ArrayList<String> inWordList)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Type a word then press enter.");
- String addToList = input.nextLine();
- inWordList.add(addToList);
- }
- public static void displayList(ArrayList<String> inWordList)
- {
- for(String s : inWordList)
- {
- System.out.println(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment