This assignment is about creating a variant of a well-known word game whereby a player is presented with a number (in this case 10) of randomly chosen letters from the alphabet (the letter pool) and they are expected to come up with words that can be formed with those letters. The game is usually played under the challenge of time but in this version the player will have a limited number of trials (in this case 10) for entering words. Thus, the player will be able to enter a maximum of 10 words that can be made from the letter pool.

For each word that the user enters (i.e. during each turn) they can use all the letters of the pool. The score of each successful word entered by the player is equal to the length of the word in characters. The total score of the game run is the sum of all scored/valid words entered by the user. A word will contribute to the score if:

  • it has not been submitted before in the game,
  • it is possible to form it from the letters in the letter pool and
  • it exists in a dictionary of valid words.

The dictionary of valid words for the game is given to you in the project folder and it is called brit-a-z.txt.

Here is an example of how your completed program should behave:

Trial 1 of 10:
N R A C X F L E N Y
Enter word: car
3 points for CAR!

Trial 2 of 10:
N R A C X F L E N Y
Enter word: ran
3 points for RAN!

Trial 3 of 10:
N R A C X F L E N Y
Enter word: flex
4 points for FLEX!

Trial 4 of 10:
N R A C X F L E N Y
Enter word: lend
LEND is an invalid word!

Trial 5 of 10:
N R A C X F L E N Y
Enter word: ran
RAN was entered earlier

Trial 5 of 10:
N R A C X F L E N Y
Enter word: race
4 points for RACE!

Trial 6 of 10:
N R A C X F L E N Y
Enter word: fan
3 points for FAN!

Trial 7 of 10:
N R A C X F L E N Y
Enter word: can
3 points for CAN!

Trial 8 of 10:
N R A C X F L E N Y
Enter word: fen
3 points for FEN!

Trial 9 of 10:
N R A C X F L E N Y
Enter word: ann
ANN not in dictionary.

Trial 10 of 10:
N R A C X F L E N Y
Enter word: near
4 points for NEAR!

Total score: 27

Notice the following:

In each trial the trial number is reported and the letter pool (i.e. the 10 letters randomly chosen in each game) is presented to the user. The user is then prompted for input. The users input is shown in bold for clarity. Following the users input the program checks the word submitted and scores it if it is valid otherwise the problem is reported.

In trial 4, for example, the user enters the word lend. This is an invalid word because it cannot be composed using the letter pool. The trial is lost as a penalty.

In trial 5 the user enters the word ran. This word was entered earlier in trial 2 so the user earns no more points and the trial is not lost. Notice that the user is allowed to re-enter for trial 5.

In trial 9 the user enters the word ann. This word is not in the dictionary. The trial is lost as a penalty.

For all other trials the words supplied by the user are valid and the score of each word is reported to the user.

Finally, the total score is reported to the user and the game run ends.

Please study and make sure you understand the existing code in the project before proceeding to add your own to it. You are expected to make use of the code that is available to you.

Here are a few helpful comments:

The valid words from the dictionary file (brit-a-z.txt) are loaded in a Dictionary object called dictionary at the beginning of the code. The dictionary contains just under 80,000 words in lowercase. You need to figure out how you can access each word in the dictionary. Why dont you try to print the words of the dictionary on the console as a test of your ability to do this?

Two methods are also implemented for you:

getRandomLetter returns a random (uppercase) letter from the alphabet every time it is called.

validWord takes as parameters a word (String object) and an array of characters (char data type). It returns a boolean value which is true if the word supplied can be made up using the characters in the supplied array and false if not. Note that the check performed in this method is case sensitive. For example, the method will return false if the string ball is passed with the array {L, K, B, L, Q, A, R, H,E}.

Please do not make any changes to these two methods or to the Dictionary class.

The project can be broken down into smaller subtasks. Spend some time in order to identify and order these subtasks on paper before you start coding.

Once this is done it will be easier to write and test the code for each subtask in turn.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.