Question: Urgent! Urgent!!!!!! import java.io . File; import java.io . FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextArea; public class Project

Urgent! Urgent!!!!!!
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
public class Project1 extends JFrame {
private static final int MIN_WORD_LENGTH =5;
private String puzzleLetters;
private ArrayList solutions;
private JTextArea foundWordsArea;
private JLabel scoreLabel;
public Project1(String fileName) throws FileNotFoundException {
super("Spelling Beehive");
this.solutions = new ArrayList<>();
this.readInput(fileName);
this.createGUI();
this.scoreLabel.setText("Score: 0");
}
private void readInput(String fileName) throws FileNotFoundException {
File file = new File(fileName);
Scanner scanner = new Scanner(file);
this.puzzleLetters = scanner.nextLine().toUpperCase();
while (scanner.hasNextLine()){
solutions.add(scanner.nextLine().toUpperCase());
}
scanner.close();
}
private void createGUI(){
PuzzleGUI puzzleGUI = new PuzzleGUI(puzzleLetters);
this.add(puzzleGUI);
this.setSize(400,200);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void playGame(){
while (true){
String guess = JOptionPane.showInputDialog(this, "Enter a word (at least 5 letters):").toUpperCase();
if (guess == null){
break;
}
if (!isValidWord(guess)){
continue;
}
if (solutions.contains(guess)){
foundWordsArea.append(guess +"
");
solutions.remove(guess);
scoreLabel.setText("Score: "+ foundWordsArea.getLineCount());
} else {
JOptionPane.showMessageDialog(this, "Invalid guess!");
}
}
}
private boolean isValidWord(String guess){
if (guess.length()< MIN_WORD_LENGTH){
JOptionPane.showMessageDialog(this, "Word must be at least 5 letters long!");
return false;
}
for (char letter : guess.toCharArray()){
if (!puzzleLetters.contains(String.valueOf(letter))){
JOptionPane.showMessageDialog(this, "Word contains invalid letters!");
return false;
}
}
return true;
}
public static void main(String[] args){
if (args.length !=1||!args[0].equals("P1input.txt")){
System.out.println("Usage: java Project1 P1input.txt");
System.exit(1);
}
try {
Project1 game = new Project1(args[0]);
game.playGame();
} catch (FileNotFoundException e){
System.out.println("Error: Input file not found!");
e.printStackTrace();
}
}
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class PuzzleGUI extends JPanel {
private JTextArea foundWordsArea;
private JLabel scoreLabel;
public PuzzleGUI(String puzzleLetters){
this.setLayout(new java.awt.GridLayout(1,2));
JLabel letterLabel = new JLabel("Puzzle Letters: "+ puzzleLetters);
foundWordsArea = new JTextArea();
foundWordsArea.setEditable(false);
scoreLabel = new JLabel("Score: 0");
this.add(letterLabel);
this.add(foundWordsArea);
}
public JTextArea getFoun
Improving on the Word Game Add the following improvements to the word game. (1) The first letter of the subject letters (the first line of the input file) must be contained in all the correct guessed words. (2) If a guessed word contains ALL of the subject letters, that is worth 3 points. (3) Display the correctly guessed words in alphabetical order. Lists of Words Create a class called WordNode which has fields for the data (a Word) and next (WordNode) instance variables. Include a one-argument constructor which takes a Word as a parameter. (For hints, see the PowerPoint on "Static vs. Dynamic Structures.) public WordNode (Word w){..} The instance variables should have protected access. Create an abstract linked list class called WordList. This should be a linked list with head node as described in lecture. Modify it so that the data type in the nodes is Word. The no-argument constructor should create an empty list with first and last pointing to an empty head node, and length equal to zero. Include an append method in this class. Create two more linked list classes that extend the abstract class WordList: One called UnsortedWordList and one called SortedWordList, each with appropriate no-argument constructors. Each of these classes should have a method called add(Word) that will add a new node to the list. In the case of the UnsortedWordList it will add it to the end of the list by calling the append method in the super class. In the case of the SortedWordList it will insert the node in the proper position to keep the list sorted. Instantiate two linked lists, one sorted and one unsorted. Add the solutions from the input file to the unsorted linked list. This list will be searched to see if a guessed word matches. As words are correctly guessed, add them to the sorted list and display the contents of that list in the TextArea for the guessed words. Check the method setText in class TextArea to update the contents of the TextArea.
Now write the improvement of this code withing today to get good review!

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