The following text was written to the standard output stream when the WordList.java program was executed from Netbeans.
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package arraylistplay; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; /** * * @author ecuevas */ public class WordList { /** * @param args the command line arguments */ private static ArrayListwords = new ArrayList<>(); private static int numberOfWords = 0; private static Scanner commandReader = new Scanner(System.in); /** * @param args the command line arguments */ public static void main(String[] args) { try { readWords(); interpreter(); } catch (FileNotFoundException ex) { System.out.println("The file was not found. Please think again."); System.exit(-1); } } private static Scanner establishScanner(String fn) throws FileNotFoundException { String separator = System.getProperty("file.separator"); String homeDirectory = System.getProperty("user.home"); String path = homeDirectory + separator + "CS1Files" + separator + "data" + separator; String fullFileName = path + fn; return new Scanner(new File(fullFileName)); } private static void readWords() throws FileNotFoundException { Scanner scanner = establishScanner("WordSet2.text"); while (scanner.hasNext()) { words.add(numberOfWords,scanner.next()); numberOfWords = numberOfWords + 1; } } private static void displayWords() { for (String word : words) { System.out.println(word); } } private static void interpreter() { System.out.print(">>>"); String command = commandReader.next(); if (command.equalsIgnoreCase("DISPLAY")) { interpreterDisplayCommand(); } else if (command.equalsIgnoreCase("PRINT")) { interpreterPrintCommand(); } else if (command.equalsIgnoreCase("SWAP")) { interpreterSwapCommand(); } else if (command.equalsIgnoreCase("ADD")) { interpreterAddCommand(); } else if (command.equalsIgnoreCase("HELP")) { interpreterHelpCommand(); } else if (command.equalsIgnoreCase("EXIT")) { System.exit(0); } else { System.out.println("### Unrecognizable command: " + command); } System.out.print("\n"); interpreter(); } private static void interpreterDisplayCommand() { displayWords(); } private static void interpreterPrintCommand() { String operand = commandReader.next(); if (operand.equalsIgnoreCase("FIRST")) { System.out.println(words.get(0)); } else if (operand.equalsIgnoreCase("LAST")) { System.out.println(words.get(words.size() - 1)); } else { int index = Integer.valueOf(operand); System.out.println(words.get(index-1)); } } private static void interpreterSwapCommand() { int position1 = commandReader.nextInt(); int position2 = commandReader.nextInt(); String temp = words.get(position1); words.set(position1,words.get(position2)); words.set(position2,temp); } private static void interpreterAddCommand() { if(isNumeric()) { int index = commandReader.nextInt()-1; String nextWord = commandReader.next(); if (index > numberOfWords) { System.out.println("### invalid operand for add command"); } else { words.add(index,nextWord); } } else{ } String position = commandReader.next(); if (position.equalsIgnoreCase("Last")) { words.add(words.size(), commandReader.next()); } else if (position.equalsIgnoreCase("FIRST")) { words.add(0,commandReader.next()); } else { System.out.println("### invalid operand for add command"); } numberOfWords = numberOfWords + 1; } private static void interpreterHelpCommand() { System.out.println("HELP - display menu of commands"); System.out.println("DISPLAY - display the list of numbers"); System.out.println("PRINT - print a word (FIRST; LAST; nth)"); System.out.println("SWAP - exchange two elements (nth; mth)"); System.out.println("ADD - add a word to the list (FIRST; LAST)"); System.out.println("EXIT - terminate execution of the program"); } private static boolean isNumeric() { return commandReader.hasNextInt(); } }