$25
Learning Outcomes
In this assignment, you will get practice with:
• Creating classes and objects of those classes
• Overloading constructors
• Implementing equals(), toString(), getters, and other methods
• Working with arrays
• Using loops and conditionals
Introduction
Most of us are probably familiar with the beloved family game ‘Scrabble’. In
Scrabble, players collect seven random tiles, each consisting of a letter A through Z (for the sake of simplicity, let us that assume the ‘blank’ tile does not exist in this version of the game). Players then use these tiles to create words that consist of one or more of the letters they’ve randomly selected.
When a word is created using one or more of the seven selected tiles, the value of each of the tiles is summed, and that score is added to the player’s cumulative score. The individual value of each tile is presented below.
In this assignment, you are provided with a text file consisting of all 279,496 words published in the 2019 version of the Collins Scrabble Word dictionary.
Given the letters of seven randomized Scrabble tiles, you must determine the set of scores that a player could possibly obtain by placing these tiles. We will be assuming three traits that differ slightly from the traditional game of Scrabble:
1. There is an unlimited amount of every letter within the scrabble bag, thus it is reasonable to assume (though incredibly unlikely) that you could obtain something like [‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’, ‘A’].
2. You will be placing these tiles during the first turn on the board. Thus, you do not need to worry about combining your word with any pre-existing letters that might have already been placed on the Scrabble board.
3. Assume that there exist no word or letter bonuses. We will simply be basing the score off the tile values.
As an example, assume that your seven randomized tiles read:
{‘A’, ‘C’, ‘A’, ‘A’, ‘B’, ‘A’, ‘H’}
The output should be 1) a list of length n of words that can be created using these letters, and 2) a list of length n containing the scores (integers) for each of the words of length 1 ≤ m ≤ 7 that can be created using these letters (like ‘AA’, or ‘AAH’, which are both words within the Collins Scrabble Word dictionary, surprisingly). So two of the scores that will be in your score set for the above tile set are 2 (A (1) + A (1) = 2), and 6 (A (1) + A (1) + H (4) = 6).
Provided Files
The following is a list of files provided to you for this assignment. Do NOT alter these files.
- CollinsScrabbleWords2019.txt
- TestGame.java
Classes to Implement
For this assignment, you must implement two java classes: Tile and Scrabble. Follow the guidelines for each one below.
In these classes, you can implement more private (helper) methods if you want to. You may not, however implement more public methods. You may not add instance variables other than the ones specified below nor change the variable types or accessibility (i.e. making a variable public when it should be private). Penalties will be applied if you implement additional instance variables or change the variable types of modifiers from what is described here.
Tile.java
This class represents a single Scrabble tile that will be used in the game.
The class must have the following private variables:
• value (char)
The class must have the following public methods:
• public Tile() [constructor] o Initialize value to ‘ ’
• public Tile(char) [constructor] o Initialize value to the given argument
• public void pickup() o Generate a random character between A and Z (inclusive) and set the value to that letter. o Feel free to use ‘java.util.random’ for this method
• public char getValue() o Returns the tile value
Scrabble.java
This class represents the Scrabble game in which there are seven randomly selected tiles, and scoring is performed for each possible word (this will be the tougher class to implement).
The class must have the following private variables: • Tile (Tile[ ])
The class must have the following public methods:
• public Scrabble() [constructor] o Initialize the Tile array and ‘pickup’ for random values
• public Scrabble(Tile [ ]) [constructor] o Initialize the tile array with the given argument
• public String getLetters() o Return a string that is all of the tile characters (for example, “ABFEODL”)
• public ArrayList<String> getWords() o Create a String array with sn elements. Each element in this list should represent a word that can be created using the current tiles.
o The algorithm for this method should reference the provided file
CollinsScrabbleWords2019.txt o ** do NOT put this file somewhere on your local machine and hardcode the local directory. This will likely cause your tests to fail on GradeScope. Also, do not put it within a folder in the relative path.
• public int[ ] getScores() o Create an int array with n elements. Each element in this list should represent each individual score for each word that can be created using the current tiles. This should be returned in ascending order.
• public Boolean equals(Scrabble) o Compare the given Scrabble object from the argument with the ‘this’ object to see if they are equal.