Page 1 of 1
Word.java This class represents a word in the game that is comprised of any number of letters. Each letter is represente
Posted: Tue Jul 12, 2022 8:09 am
by answerhappygod

- Word Java This Class Represents A Word In The Game That Is Comprised Of Any Number Of Letters Each Letter Is Represente 1 (66.56 KiB) Viewed 54 times

- Word Java This Class Represents A Word In The Game That Is Comprised Of Any Number Of Letters Each Letter Is Represente 2 (40.34 KiB) Viewed 54 times
Word.java This class represents a word in the game that is comprised of any number of letters. Each letter is represented by a Letter object. The Letter objects are stored in a linked list formed by objects of the class LinearNode. Each node in the linked list stores an object of the class Letter. The most important instance method of this class is labelWord which labels Letter objects with respect to a mystery word. This is the trickiest method of this assignment. The class must have the following private variables: firstLetter (LinearNode<Letter>): A reference to the first node in the linked list representing the word corresponding to this object. The class must have the following public methods: public Word (Letter[] letters) [constructor] Initialize the Word object so the Letter objects in array "letters" is stored within its linked structure. Instance variable firstLetter must point to the first node of the linked list. For example, the invocation to the constructor passing as parameter an array of Letter objects corresponding to guess "BOOK" in page 1 would create the following linked list: firstLetter 'B' UNSET '0' USSET 'O' UNSET Object of class LinearNode 'K' UNSET Object of class Letter public String toString() Creates a String of the form: "Word: L1 L2 L3... Lk", where each Li is the string produced by invoking the toSting method on each Letter object of this Word.
• from the Introduction, we can see examples of the output of this toString() method: "Word: +A+ -C--C--E- -P- -T-" + "Word: -B--0--0--K-" . public boolean labelWord (Word mystery) takes a mystery word as a parameter and updates each of Letters' "label" attribute contained in this Word object with respect to the mystery word returns true if this word is identical in content to the mystery word To understand how the "label" attribute of the Letter objects stored in the linked list of a Word object are updated, consider an example. Suppose that the mystery word is "APPLE" and that this object stores Letter objects corresponding to the word "BOOK", then the "label" attributes of the Letter objects would be updated as follows: + label for Letter object corresponding to 'B' is UNUSED + label for Letter object corresponding to 'O' is UNUSED + label for Letter object corresponding to 'O' is UNUSED + label for Letter object corresponding to 'K' is UNUSED