Homeworks 2 & 3: Shortcut Scrabble
Updated on Sep 12, 2026
Starter code is not provided for this homework.
- HW2: Implement
Letter.java. Create ahw2folder inside yourCS159/hwsfolder to hold it. - HW3: Implement
Hand.javaandBoard.javainside ahw3folder in yourCS159/hwsfolder, and download the providedPlayScrabble.javainto that same folder.
Since Hand and Board both use Letter, you’ll need to import it. Assuming your Letter.java code is in the correct hw2 folder, add this line before the class declaration in both Board.java and Hand.java:
import hw2.Letter;
Please review the Grading Criteria at the end of this page before you start programming.
Learning Objectives
After completing this homework, you should be able to:
- Create classes with attributes and methods.
- Instantiate objects from classes.
- Utilize constructor methods to initialize object properties.
- Implement methods to manipulate object data.
This assignment must be completed individually. Your work must comply with the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 159, and the instructor. Copying code from someone else, including the use of generative AI, is prohibited and will be grounds for a reduced or failing grade in the course.
Introduction
Scrabble is a game where players get a set, or “hand”, of wooden pieces, each one with a letter and point value on it. On their turn the player forms a word using some of the letters from their hand and places them on the board. The board has places for the wooden pieces, marked with special symbols, some of which will have a “multiplier” effect on the letter point value that is played in that location. In the real Scrabble, the board is a large square and letters must be played in such a way that each word connects to the others that have been played similar to a crossword puzzle.
The Short Cut Scrabble aims to create a simplified version of the traditional Scrabble board game. In this assignment, we will implement two essential classes, Letter.java and Hand.java, based on the provided UML diagrams. The game involves a single horizontal strip as the board, and players score points by strategically placing words on this strip. We will implement more classes related to Scrabble game in homework 5 and 6.
UML Diagram
classDiagram
classDef redBox fill:#f8d7da,stroke:#e53935,stroke-width:2px,color:#000
class PlayScrabble:::providedCodeNoEdit
cssClass "PlayScrabble" redBox
<<utility>> PlayScrabble
PlayScrabble: +main(args String[])$ double
class Board
Board: -Letter[] board
Board: -int[] pointMult
Board: +Board(multiplier int[])
Board: +getLetter(index int) Letter
Board: +getPointMult(index int) int
Board: +getBoardScore() int
Board: +play(letter Letter, index int) boolean
Board: +getLetterScore(index int) int
Board: +toString() String
class Hand
Hand: +int MAX_SIZE{ =8 readonly}$
Hand: -Letter[] hand
Hand: -int size
Hand: +Hand(size int)
Hand: +Hand()
Hand: +getSize() int
Hand: +getLetter(index int) Letter
Hand: +insert(letter Letter, index int) boolean
Hand: +remove(index int) Letter
Hand: +indexOf(letter char) int
Hand: +toString() String
class Letter
Letter: -char letter
Letter: -int points
Letter: +Letter(letter char, points int)
Letter: +getLetter() char
Letter: +getPoints() int
Letter: +equals(other Letter) boolean
Letter: +toString() String
PlayScrabble -- Board
PlayScrabble -- Hand
Hand -- Board
Hand -- Letter
Board -- Letter
Create Letter.java
Letter.java The Letter class represents an individual letter tile in the game. Implement the class and methods according to the UML and specifications.
Letter Constructor and Accessors The Letter constructor and accessors should be implemented to initialize the character and points with the constructor parameters as shown.You can assume that the arguments passed to the constructor parameters will be correct. In other words, no parameter checks are required.
Mutator methods The setLetter and the setPoints methods should be implemented to update instance variables letter and points.
Accessor methods The getLetter and the getPoints methods should be used to return the values of instance variables letter and points.
equals The equals method should return true if both the character and the point value associated with this letter are equal to the character and point value of the other letter.
toString The toString method should return a String describing the letter consisting of the character followed by colon, then followed by the points. For example the String returned by a Letter with letter assigned ’t’ and points assigned 3 will be: “t:3”
Create Hand.java
Implement the class and methods according to the UML and specifications. The Hand class represents the player’s hand, which holds a collection of Letter tiles.
Hand The no-argument constructor should create a hand of MAX_SIZE.
Hand(int size) This constructor should create a hand of size. If size is less than zero, a hand of size zero should be created. If size is greater than MAX_SIZE, a hand of MAX_SIZE should be created.
insert If index is within range and there is not another letter in the hand at index, the letter should be inserted into the hand at index and return true. If those conditions do not hold, false should be returned.
For example:
// assume the MAX_SIZE is 8 in the Hand class
Hand hand = new Hand();
System.out.println(hand.insert(new Letter(‘A’, 1), 0) // true
System.out.println(hand.insert(new Letter(‘B’, 2), 0) // false
System.out.println(hand.insert(new Letter(‘F’, 1), -1) // false
toString This method should return a String consisting of the following for each letter in the hand: the Letter toString followed by a comma. If there is no letter at index, i.e. the location is null, then insert a dash ‘-’ where the letters toString would be printed.
For example:
// assume the MAX_SIZE is 8 in the Hand class
Hand hand = new Hand(3);
hand.insert(new Letter(‘a’, 1), 1);
System.out.println(hand.insert(new Letter(‘b’, 2), 0);
System.out.println(hand) // output is “b:2,a:1,-”
remove If index is within range, the letter at index should be removed from the hand (the location set to null) and the letter that was at index returned. If there is no letter at index, return null.
indexOf This method should search through the hand and return the index of the first occurrence of the letter. If the letter is not in the hand, return -1.
getLetter(int index) This method should return the value at the given index in the hand.
getSize This method should return the size the hand was initialized to.
Create Board.java
Board(int[] multiplier) The constructor should create an empty entries board that is the same length of the multiplier parameter and use the multiplier parameter to initialize the pointMult attribute. The pointMult attribute should be a new array that is a copy of the multiplier array (don’t just copy the reference).
getLetter(int index) These methods should get the value indicated by index. If index is out of bounds, a null value should be returned.
getPointMult(int index) These methods should get the value indicated by index. If index is out of bounds, a 0 value should be returned
getBoardScore() This method should compute and return the score of the letters currently played on the board by multiplying the corresponding indices of the point values of each letter in board and pointMult and adding them together.
For example, if we had the following entries and point multipliers,
entries: [p:1, o:1, n:1, g:2, o:1]
pointMult: [ 2, 1, 1, 2, 3]
this method would return 11 (1*2 + 1*1 + 1*1 + 2*2 + 1*3 = 11).
play(Letter letter, int index) This method should put letter into entries at index. The method should return true if index is in bounds and there is no letter at index, otherwise it should return false.
getLetterScore(int index) This method must return the point value of the letter at index multiplied by the multiplier at the same index. If index is out of bounds, or there is no letter at index, the method must return 0.
toString() This method should return a String representing the board. The String should represent the Letters (represented by its character and point value, separated with a single colon) in board, each followed by a semicolon and a single space. If an entry is null, it should be represented with a single dash (-) instead.
For example, a board with length 4 and a single Letter at index 1 (with the character of ‘a’ and the point value of 10) would be represented as below. Note that there is no space at the end.
-; a:10; -; -;
Recommended Process
Within VSCode, create a new folder/directory for this assignment, named hw2, under the hws folder.
HW2: Implement the Letter class and submit it to Gradescope
Create the Letter class under hws/hw2:
- Write up all of the methods (with appropriate signatures)
- Initially, each method should return some artificial value
- Add javadoc comments to the Letter class
- Ensure your file has no checkstyle errors
Implement the Letter class:
- Add the fields listed in the UML diagram
- Add the constructor listed in the UML diagram
- Implement the methods listed in the UML diagram
- Write accessors (getters) first
- Write the equals method
- Write the toString method
HW3: Implement the Hand class and Board class submit them to Gradescope
Create the Hand class in your hws/hw3:
- Repeat the above steps for
Hand.java - Repeat the above steps for
Board.java
Import Letter class
Since you will need to use Letter in both the Hand and Board classes, you must first import it.
Assuming that you have your code from HW2 in the correct hw2 folder, you should be able to put this line before the class declaration in both Board.java and Hand.java:
import hw2.Letter;
Test with the driver class: PlayScrabble
After you implemented the Board.java and Hand.java, you can play the game of Shortcut Scrabble Download PlayScrabble.java and place it in your CS159/hws/hw3 folder. Run PlayScrabble.java, You should see output similar to below
*** Welcome To Shortcut Scrabble ***
=========================================================
The board:
Entries: --------
Multipliers: 31211213
Points: 0
Your hand:
y:1,n:3,g:1,w:2,s:3,i:3,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
0
What letter would you like to play?
w
Played w:2 at position 0
=========================================================
The board:
Entries: w-------
Multipliers: 31211213
Points: 6
Your hand:
y:1,n:3,g:1,-,s:3,i:3,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
1
What letter would you like to play?
i
Played i:3 at position 1
=========================================================
The board:
Entries: wi------
Multipliers: 31211213
Points: 9
Your hand:
y:1,n:3,g:1,-,s:3,-,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
2
What letter would you like to play?
n
Played n:3 at position 2
=========================================================
The board:
Entries: win-----
Multipliers: 31211213
Points: 15
Your hand:
y:1,-,g:1,-,s:3,-,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
3
What letter would you like to play?
g
Played g:1 at position 3
=========================================================
The board:
Entries: wing----
Multipliers: 31211213
Points: 16
Your hand:
y:1,-,-,-,s:3,-,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
4
What letter would you like to play?
s
Played s:3 at position 4
=========================================================
The board:
Entries: wings---
Multipliers: 31211213
Points: 19
Your hand:
y:1,-,-,-,-,-,g:3,v:3
=========================================================
Where would you like to move? (0-7, 8 to quit)
8
Bye!
Grading Criteria
Your code will first be graded by Gradescope and then by the professor. The grade you receive from Gradescope is the maximum grade that you can receive on the assignment.
After the due date, the professor may manually review your code. At that time, points may be deducted for inelegant code, inappropriate variable names, bad comments, etc.
Your code must compile with the official tests and pass a Checkstyle audit for you to receive any points.
Gradescope will provide you with hints but might not completely identify the defects in your submission. You are expected to test your own code before submitting.
There is no limit on the number of submissions and no penalty for excessive submissions. Points will be allocated as follows:
| Criterion | Points | Details |
|---|---|---|
| Compile | 0 pts | Success Required |
| CompileOfficialTests | 0 pts | Success Required |
| Style | 0 pts | Success Required |
| OfficialTests for Letter class | 30 pts | Partial Credit Possible |
| OfficialTests for Hand class | 30 pts | Partial Credit Possible |
| OfficialTests for Board class | 40 pts | Partial Credit Possible |