Introduction
This assignment is intended to be a chance for you to review concepts from CS149 by completing a miniature PA (Programming Assignment). You will implement two of the classes to play Short Cut Scrabble. 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. In Short Cut Scrabble, the board is just a single horizontal strip and a player just plays by inserting their word on the board to get points.
You should implement the two classes, Letter.java
and Hand.java
, from the UML diagram below. The other classes shown, Board.java
and PlayScrabble.java
are provided for you, along with tests for each of the classes you should implement.
Provided Files (no modifications are expected or permitted)
Implementation
Tests
Other than only the slightest modifications (to help the autograder award/deduct points) these are precisely the tests that the autograder (gradescope) will use to test your code. You should run these tests to make sure your code is working correctly before submitting your code to gradescope.
UML Diagram
classDiagram
class PlayScrabble:::providedCodeNoEdit
<<utility>> PlayScrabble
PlayScrabble: +main(args String[])$ double
class Board:::providedCodeNoEdit
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
Part 1 - Create Letter.java
Implement the class and methods according to the UML and specifications below.
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.
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 “Letter: " with one space after the colon followed by the character, another space, then “Points: " followed by the points. For example the String returned by a Letter with letter assigned ’t’ and points assigned 3 will be: “Letter: t Points: 3”
Part 2 - Create Hand.java
Implement the class and methods according to the UML and specifications below. When implementing these methods make sure to avoid code duplication by using other methods in the class as appropriate.
Hand
The default 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.
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.
toString
This method should return a String consisting of the following for each letter in the hand: index
followed immediately by a colon, then a space, then the Letter toString followed by a semicolon, and a final space. If there is no letter at index
, i.e. the location is null, then insert a dash ‘-’ where the letters toString would be printed.
indexOf
This method should search through the hand and return the index
of the first occurrence of 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.
Submission and Grading
You should never start design or construction until you completely understand the project.
You should start by carefully reading the project specifications. (In general it is a good idea to print a paper copy so that you can take notes and perform calculations as you read.)
Implement all of the classes (in accordance with the specifications, perhaps informed by the Implementation Advice above) and submit them to gradescope .
You are not required to submit tests for these classes.
Grading
Project Part | Weight |
---|---|
Checkstyle | 20% |
Correctness | 80% |
You may submit to Gradescope an unlimited number of times.
Recommended Process
Since nobody will be looking over your shoulder, you can use any process that you would like to use. However, it is strongly recommended that you use the process described here.
Get Started
- π Read and π§ understand the entire assignment.
- to each their own and all, but if your metacognitive skills are anything like mine were(n’t) π¬ when I was taking a similar class back in my day, you may find it worthwhile to print the specs out and read them with a pen ποΈ or highlighter in hand π. This is also makes for a convenient tool π οΈ with which to accost your favorite TA or instructor π©βπ« with questions in the hallway, strolling campus, or wherever you find them π₯· (“Office Hours” are always great of course).
- π Write down any questions you have about the assignment.
- if you have any questions about the assignment, ask your classmates, TA, or instructor.
- If you’ve gotten to this step in the process at least 5 days before the assignment’s deadline ποΈ, you basically gave yourself bonus points π.
- Perhaps you’d like a prof to cite a source when they claim such things? Check it: π¬ Students who got earned an A or B on an an assignment started on average 4 days earlier that students who earned lower scores on the same assignment. Further, both groups of students (A/B and C/D/F) spent about the same amount of time on the assignment! π€― (Edwards, et al. 2008)
- Create a project for this assignment named pa1. (
Remember
, do NOT create a
module-info.java
and DO create separate folders for source and class files). 3.Activate Checkstyle
for this assignment. - Add the provided code to your project, directly in the
src
folder.- You may need to right click on the project and choose
Refresh
to see the new files in Eclipse.
- You may need to right click on the project and choose
Stub it out
- Create the
Letter
class in your project.- it should contain all of the methods (with appropriate signatures), each of which should
return
some artificial value (e.g.return 0;
orreturn null;
,return false;
) for now.- Note: you may wish to add a comment in the code any time you write code that you intend to replace later. For example, you might write
// TODO: replace this with real code
or// FIXME: implement this method
.
- Note: you may wish to add a comment in the code any time you write code that you intend to replace later. For example, you might write
- it should contain all of the methods (with appropriate signatures), each of which should
- Add the <code>javadoc</code> comments to the
Letter
class.- For reference on javadoc syntax, take a look at the provided classes.
- Ensure your file has no checkstyle errors (you’ll likely want to take advantage of the autoformatter here by choosing
Format
from theSource
menu in Eclipse). - At this point, there should be no errors (Java nor Checkstyle) in your
Letter
class. - (repeat the above for
Hand
.) Create theHand
class in your project.- it should contain all of the methods (with appropriate signatures), each of which should
return
some artificial value (e.g.return 0;
orreturn null;
,return false;
) for now.- Note: you may wish to add a comment in the code any time you write code that you intend to replace later. For example, you might write
// TODO: replace this with real code
or// FIXME: implement this method
.
- Note: you may wish to add a comment in the code any time you write code that you intend to replace later. For example, you might write
- it should contain all of the methods (with appropriate signatures), each of which should
- Add the
javadoc
comments to theHand
class.- For reference on javadoc syntax, take a look at the provided classes.
- Ensure your file has no checkstyle errors (you’ll likely want to take advantage of the autoformatter here by choosing
Format
from theSource
menu in Eclipse). - At this point, there should be no errors (Java nor Checkstyle) in your
Hand
class, and neither in this project at all.
π‘Tip
From this point onward, you should have no errors or warnings from Checkstyle and neither from Java in this project unless you save in the middle of typing a statement.Run the unit tests
- run the unit tests for the project.
- right-click on the project int he sidebar of eclipse
- choose
Run As
->JUnit Test
. - you should see that all or most of the tests fail.
π‘Tip
From this point onward, each time you implement another method or 2 you should be able to pass more of these tests. So run the tests like this often.Implement the Letter
class
- add the fields listed in the UML diagram.
- add the π constructor listed in the UML diagram.
- add the methods listed in the UML diagram.
- write the
accessors
(also calledgetters
) first.- note: did you notice the Checkstyle error about missing javadoc comments for these methods? (no, you didn’t because if you wrote these methods according to the specifications, and have Checkstyle configured correctly, it will not complain about missing javadoc comments for these methods π. If you’re curious about why, check out <code>allowMissingPropertyJavadoc</code> in the CHeckstyle docs )
- write the
equals
method - write the π§΅
toString
method
- write the
Implement the Hand
class
- add the fields listed in the UML diagram.
- add the π constructors listed in the UML diagram.
- add the methods listed in the UML diagram.
- write the
accessors
(also calledgetters
) first. - write the π§΅
toString
method - write the
insert
method - write the
remove
method - write the
indexOf
method
- write the
Test with the driver class: PlayScrabble
- right-click on the project and choose
Run As
->Java Application
.- Eclipse will look for which class has the
main
method and run that. In this project that should only bePlayScrabble
.
- Eclipse will look for which class has the
- You should see output similar to the depiction in a later section.
- Notice that the game waits for you to type a number or letter and then press enter after each to continue its work.
Ensure that all of the provided tests pass
- Run the unit tests for the project.
- right-click on the project int he sidebar of eclipse
- choose
Run As
->JUnit Test
.
- you should see that all of the tests pass (in which you already know the score you will get from Gradescope! π―)
Help
- Eclipse (other than the docs on this site), you might like to peruse the relevant part so the wiki, e.g. Eclipse@JMU CS Wiki
- Go to your professor’s office hours
- Go to TA Hours
Example Game
*** Welcome To Shortcut Scrabble ***
=========================================================
The board:
Entries: --------
Multipliers: 31211213
Points: 0
Your hand:
0: Letter: v Points: 3; 1: Letter: u Points: 4; 2: Letter: n Points: 2; 3: Letter: y Points: 0; 4: Letter: g Points: 3; 5: Letter: i Points: 0; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
0
What letter would you like to play?
v
Played Letter: v Points: 3 at position 0
=========================================================
The board:
Entries: v-------
Multipliers: 31211213
Points: 9
Your hand:
0: -; 1: Letter: u Points: 4; 2: Letter: n Points: 2; 3: Letter: y Points: 0; 4: Letter: g Points: 3; 5: Letter: i Points: 0; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
1
What letter would you like to play?
y
Played Letter: y Points: 0 at position 1
=========================================================
The board:
Entries: vy------
Multipliers: 31211213
Points: 9
Your hand:
0: -; 1: Letter: u Points: 4; 2: Letter: n Points: 2; 3: -; 4: Letter: g Points: 3; 5: Letter: i Points: 0; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
2
What letter would you like to play?
i
Played Letter: i Points: 0 at position 2
=========================================================
The board:
Entries: vyi-----
Multipliers: 31211213
Points: 9
Your hand:
0: -; 1: Letter: u Points: 4; 2: Letter: n Points: 2; 3: -; 4: Letter: g Points: 3; 5: -; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
3
What letter would you like to play?
n
Played Letter: n Points: 2 at position 3
=========================================================
The board:
Entries: vyin----
Multipliers: 31211213
Points: 11
Your hand:
0: -; 1: Letter: u Points: 4; 2: -; 3: -; 4: Letter: g Points: 3; 5: -; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
4
What letter would you like to play?
g
Played Letter: g Points: 3 at position 4
=========================================================
The board:
Entries: vying---
Multipliers: 31211213
Points: 14
Your hand:
0: -; 1: Letter: u Points: 4; 2: -; 3: -; 4: -; 5: -; 6: Letter: m Points: 3; 7: Letter: a Points: 0;
=========================================================
Where would you like to move? (0-7, 8 to quit)
8
Bye!