- All Known Implementing Classes:
StaticWordSet
WordSet
interface defines the contract for managing a set of
words with functionalities such as retrieving the total number of characters,
getting a randomly selected "correct" word, shuffling the word list, and
generating a jumbled string with symbols inserted between the words.
Implementations of this interface are expected to provide mechanisms for managing word-based operations that might be used in games or text manipulation applications.
- Version:
- 1.0
- Author:
- Kheagen Haskins
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addDudCountListener
(javafx.beans.value.ChangeListener<? super Number> cl) Adds a listener to monitor changes in the count of "dud" words.Retrieves the correct word from the word set.int
Calculates and returns the total number of characters across all words in the word list.jumble
(int size) Generates a string of the specified size by inserting random symbols between the words.boolean
Removes a specified "dud" word from the word set and returns it.Returns a word from the word set that is intentionally incorrect or invalid.shuffle()
Shuffles the words in the word list.
-
Method Details
-
getTotalCharacters
int getTotalCharacters()Calculates and returns the total number of characters across all words in the word list.- Returns:
- the total number of characters in all words within this
WordSet
.
-
getCorrectWord
String getCorrectWord()Retrieves the correct word from the word set.The "correct" word is typically one that is randomly selected during the initialisation of the implementing class. This word can be used as an answer or reference in word-based games or applications.
- Returns:
- the correct word as a
String
from the word set.
-
removeRandomDud
String removeRandomDud()Returns a word from the word set that is intentionally incorrect or invalid.The "dud" word is typically used in scenarios where an incorrect option is needed, or tests where the player or user is required to identify or differentiate between correct and incorrect words. This method complements the
getCorrectWord()
method by providing an alternative that should not be chosen as the correct answer.- Returns:
- a word as a
String
that is not the correct answer or is intentionally incorrect.
-
removeDud
Removes a specified "dud" word from the word set and returns it. This method is used in scenarios where an incorrect or invalid word needs to be removed, such as when refreshing the list of dud words or managing dynamic word sets.The "dud" word is typically used in scenarios where an incorrect option is needed, or tests where the player or user is required to identify or differentiate between correct and incorrect words. This method complements the
getCorrectWord()
method by ensuring the specified dud word is not chosen as the correct answer and is effectively managed or removed from potential selections.- Parameters:
dud
- the word to be removed from the set, specified as aString
. This word should already exist in the current set of dud words.- Returns:
- a boolean indicating if the given dud is correctly removed.
-
addDudCountListener
Adds a listener to monitor changes in the count of "dud" words.This method allows you to attach a
ChangeListener
that will be notified whenever the value of thedudCountProperty
changes. This is particularly useful in scenarios where you need to react to changes in the number of incorrect or invalid words within the application, such as updating the user interface or triggering certain actions when the count changes.- Parameters:
cl
- theChangeListener
to add; it must be able to handleNumber
type values, as the listener will receive updates whenever the count changes.
-
shuffle
WordSet shuffle()Shuffles the words in the word list.Implementations should use a randomization algorithm, such as the Fisher-Yates shuffle, to ensure each permutation of the word list is equally likely.
- Returns:
- the
WordSet
object with its words rearranged in a random order.
-
jumble
Generates a string of the specified size by inserting random symbols between the words.The generated string should include each word from the list with random symbols added between them to reach the specified size. Implementations should ensure that the resulting string matches the requested size.
- Parameters:
size
- the desired size of the game string.- Returns:
- the generated game string.
- Throws:
IllegalArgumentException
- if the specified size is too small for the total character count.
-