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 Project2, 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 Project2{
public static void main(String[] args){
String filePath ="/Users/senorking/Desktop/Fall 2023/MyJavaProject/src/P1input.txt";
String subjectLetters =""; // Initialize subject letters
// Read subject letters from input file
try {
File inputFile = new File(filePath);
Scanner scanner = new Scanner(inputFile);
subjectLetters = scanner.nextLine().trim(); // Read subject letters
scanner.close();
} catch (FileNotFoundException e){
System.out.println("Input file not found.");
e.printStackTrace();
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 = getWordsFromFile(filePath);
for (String solution : correctWords){
// Check if the guessed word contains all subject letters
if (containsAllLetters(solution, subjectLetters)){
// Award 3 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.println("Guessed word '"+ solution +"' scored 3 points!");
}
unsortedList.add(new Word(solution));
}
// Add solutions to the sorted list and display in GUI
WordNode current = unsortedList.first.next; // Skip the head node
while (current != null){
sortedList.add(current.data);
gui.displaySorted(sortedList);
current = current.next;
}
}
// Helper method to check if a word contains all letters from a given string
private static boolean containsAllLetters(String word, String letters){
for (int i =0; i letters.length(); i++){
if (word.indexOf(letters.charAt(i))==-1){
return false;
}
}
return true;
}
// Method to read words from file
private static ArrayList getWordsFromFile(String filePath){
ArrayList words = new ArrayList>();
try {
File file = new File(filePath);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()){
String word = scanner.nextLine().trim();
words.add(word);
}
scanner.close();
} catch (FileNotFoundException e){
System.err.println("File not found: "+ filePath);
}
return words;
}
}
///////////
The P1input.txt contains:
latipmo, aioli, allot, appall, atilt, atoll, impala, laptop, lollipop, lotto, mallot, mammal, militia, moola, optimal, palatial, papal, pilot, plait, polio, tilapia, total
I have most os the code. I have Project 2 ,

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 Programming Questions!