Question: HELP IN JAVA: this is an exercise in using the java LinkedList class. Using input file words.txt create a LinkedList BUT you must NOT add

HELP IN JAVA: this is an exercise in using the java LinkedList class.

Using input file words.txtHELP IN JAVA: this is an exercise in using the java LinkedList create a LinkedList BUT you must NOT add a word that is already in the list and you MUST add them in the order received to the end of the list.

For example, if your input was cat, cat, dog, mouse, dog, horse

your list would now contain cat, dog, mouse, horse. And the head of the list would be cat, and the tail would be horse. Note: it is NOT sorted.

This list represents a code, and the code for one word is the next word in the list. So the code for cat is dog and the code for mouse is horse, and the code for horse is cat(go round to the head of the list).

Now ask your user for a phrase (input from the keyboard) and output the coded phrase. In the above example if the input was "mouse cat" the output would be "horse dog". The input words will always be in the list.

I need help printing out this part This list represents a code, and the code for one word is the next word in the list. So the code for cat is dog and the code for mouse is horse, and the code for horse is cat(go round to the head of the list).

What I have so far:

public class H5 { public static String ListSearch(LinkedList list, String key){ String x = null; if (key.equals(list.getLast())){ return list.getFirst(); } else for(int i = 0;i aList) { for(String currentString : aList){ System.out.println(currentString); } } public static void main(String[] args) { File File1 = new File("words.txt"); Scanner fileInput = null; Scanner s = new Scanner (System.in); String userInput = null; try { fileInput = new Scanner(File1); } catch (FileNotFoundException e) { } LinkedList list = new LinkedList(); while (fileInput.hasNextLine()){ list.add(fileInput.nextLine()); } printList(list); System.out.println("Input characters with a comma seperating the two words: "); userInput = s.nextLine(); ListSearch(list, userInput); } }

words.txt:

puff imperatively executrix happening avoid turnbuckle inaccuracy relatedness seismology

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!