Question: I have most os the code. I have Project 2 , WordGUI, Sorted , Unsorted, WordNode, WordList and word. I need to compare code because
I have most os the code. I have Project WordGUI, Sorted Unsorted, WordNode, WordList and word. I need to compare code because my code only opens an empty GUI. It needs to print Unsorted words from file on first column and ask the user to guess then print the correctly guessed word in right column.
public class Project
public static void mainString args
String filePath UserssenorkingDesktopFall MyJavaProjectsrcPinput.txt;
String subjectLetters ; Initialize subject letters
Read subject letters from input file
try
File inputFile new FilefilePath;
Scanner scanner new ScannerinputFile;
subjectLetters scanner.nextLinetrim; Read subject letters
scanner.close;
catch FileNotFoundException e
System.out.printlnInput file not found.";
eprintStackTrace;
return;
Instantiate unsorted and sorted linked lists
UnsortedWordList unsortedList new UnsortedWordList;
SortedWordList sortedList new SortedWordList;
Create WordGUI instance
WordGUI gui new WordGUI;
Read solutions from input file and add them to the unsorted list
ArrayList correctWords getWordsFromFilefilePath;
for String solution : correctWords
Check if the guessed word contains all subject letters
if containsAllLetterssolution subjectLetters
Award points if all subject letters are contained in the guessed word
You can implement your scoring system here
For now, let's just display a message
System.out.printlnGuessed word solution scored points!";
unsortedList.addnew Wordsolution;
Add solutions to the sorted list and display in GUI
WordNode current unsortedList.first.next; Skip the head node
while current null
sortedList.addcurrentdata;
gui.displaySortedsortedList;
current current.next;
Helper method to check if a word contains all letters from a given string
private static boolean containsAllLettersString word, String letters
for int i ; i letters.length; i
if wordindexOfletterscharAti
return false;
return true;
Method to read words from file
private static ArrayList getWordsFromFileString filePath
ArrayList words new ArrayList;
try
File file new FilefilePath;
Scanner scanner new Scannerfile;
while scannerhasNextLine
String word scanner.nextLinetrim;
words.addword;
scanner.close;
catch FileNotFoundException e
System.err.printlnFile not found: filePath;
return words;
The Pinput.txt contains:
latipmo, aioli, allot, appall, atilt, atoll, impala, laptop, lollipop, lotto, mallot, mammal, militia, moola, optimal, palatial, papal, pilot, plait, polio, tilapia, total
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
