Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Help me write a Java program will create a word ladder with definitions and allow the user to guess the words in the ladder. I
Help me write a Java program will create a word ladder with definitions and allow the user to guess the words in the ladder. I have written most of this program but seem to be stuck when testing it It declares all my guesses as wrong, even the correct ones.
Instructions:
To begin, create the Word class. The Word class must have the following public constructors and methods:
constructs a new Word object with a given word
public WordString word
returns the word in the Word object
public String getWord
adds a definition
public void addDefinitionString definition
If this is the first time this method is invoked, it returns a definition
chosen at random from all added.
Otherwise it returns the same definition it returned the previous time.
public String getDefinition
determines whether this word is the same length as prevWord with exactly one letter different
public boolean followsWord prevWord
returns true if other is a Word object that contains the same word as this Word object
public boolean equalsObject other
The Word class may not have any other public constructors or methods. All fields must be private.
The file dictionary.txt has one worddefinition pair on each line. Each line consists of the word, followed by a tab character, followed by the part of speech not used followed by another tab, followed by the definition. A word may appear on multiple consecutive lines with different definitions. You will need to
read in and parse the dictionary file. For full credit, read the file only once.
To begin the program, ask the user for the length of the word ladder and the length of the words. Then construct and print the word ladder with the words replaced by question mark strings of the correct length. After displaying the ladder, prompt the user for a word. As long as the word is in the ladder and the ladder is incomplete, continue to display the ladder and ask the user for another word. Once the
user enters an incorrect word or completes the ladder, print an appropriate message and display the complete ladder.
You may assume the user will enter only capital letters and will not guess the same word twice.
For full credit, use the Word class appropriately. Do not duplicate code from the Word class elsewhere in the program.
Requirements:
The Word class has appropriate private fields and does not contain any public methods or constructors besides those specified in the instructions.
Each method and constructor in the Word class is implemented correctly.
Correctly parse the dictionary file and set up word objects.
Get the word ladder specifications from the user and randomly generate the word ladder. The word ladder must follow the rules of word ladders one index changed per row and no repeats In some cases, this may require scrapping the word ladder in progress and trying again.
Print the word ladder properly each time it needs to be printed.
Get guesses from user and check each guess to see if it's contained in the word ladder.
At the end of the game, print an appropriate message and the complete ladder.
Code from the Word class is not duplicated in the other class.
Each method and block of code has a descriptive comment.
This is what a small part of the dictionary file looks like:
Rightful a Righteous; upright; just; good; said of persons.
Rightful a "Consonant to justice; just; as a rightful cause."
Rightful a "Having the right or just claim according to established laws; being or holding by right; as the rightful heir to a throne or an estate; a rightful king."
Rightful a "Belonging, held, or possessed by right, or by just claim; as a rightful inheritance; rightful authority."
Rightfully adv. According to right or justice.
Output example:
Enter length of word ladder:
Enter length of words in ladder:
A kick on the shins.
To envelop in a wet or dry sheet, within numerous coverings."
Alt. of Pacos
An agreement; a league; a compact; a covenant.
Enter a word: PACT
A kick on the shins.
To envelop in a wet or dry sheet, within numerous coverings."
Alt. of Pacos
PACT An agreement; a league; a compact; a covenant.
Enter a word: PACO
A kick on the shins.
To envelop in a wet or dry sheet, within numerous coverings."
PACO Alt. of Pacos
PACT An agreement; a league; a compact; a covenant.
Enter a word: PACK
A kick on the shins.
PACK To envelop in a wet or dry sheet, within numerous coverings."
PACO Alt. of Pacos
PACT An agreement; a league; a compact; a covenant.
Enter a word: PICK
That's not in the ladder!
HACK A kick on the shins.
PACK To envelop in a wet or dry sheet, within numerous coverings."
PACO Alt. of Pacos
PACT An agreement; a league; a compact; a covenant.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started