Project 1 - Shortcut Scrabble

Due Feb 3 - Shortcut Scrabble is a simplified version of Scrabble…
'SCRABBLE' spelled out on what looks like a single row of a scrabble board to match the description of 'Shortcut Scrabble' that follows in the assignment.

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

  1. PlayScrabble.java
  2. Board.java

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.

  1. LetterTest.java
  2. HandTest.java

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 PartWeight
Checkstyle20%
Correctness80%

You may submit to Gradescope an unlimited number of times.

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

  1. 📖 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).
  2. 📝 Write down any questions you have about the assignment.
    • if you have any questions about the assignment, ask your classmates, TA, or instructor.
  3. 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 🎉.
  4. 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.
  5. 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.

Stub it out

  1. 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; or return 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.
  2. Add the <code>javadoc</code> comments to the Letter class.
    • For reference on javadoc syntax, take a look at the provided classes.
  3. Ensure your file has no checkstyle errors (you’ll likely want to take advantage of the autoformatter here by choosing Format from the Source menu in Eclipse).
  4. At this point, there should be no errors (Java nor Checkstyle) in your Letter class.
  5. (repeat the above for Hand.) Create the Hand 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; or return 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.
  6. Add the javadoc comments to the Hand class.
    • For reference on javadoc syntax, take a look at the provided classes.
  7. Ensure your file has no checkstyle errors (you’ll likely want to take advantage of the autoformatter here by choosing Format from the Source menu in Eclipse).
  8. At this point, there should be no errors (Java nor Checkstyle) in your Hand class, and neither in this project at all.

Run the unit tests

  1. run the unit tests for the project.
    1. right-click on the project int he sidebar of eclipse
    2. choose Run As -> JUnit Test.
    3. you should see that all or most of the tests fail.

Implement the Letter class

  1. add the fields listed in the UML diagram.
  2. add the 🚜 constructor listed in the UML diagram.
  3. add the methods listed in the UML diagram.
    1. write the accessors (also called getters) 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 )
    2. write the equals method
    3. write the 🧵 toString method

Implement the Hand class

  1. add the fields listed in the UML diagram.
  2. add the 🚜 constructors listed in the UML diagram.
  3. add the methods listed in the UML diagram.
    1. write the accessors (also called getters) first.
    2. write the 🧵 toString method
    3. write the insert method
    4. write the remove method
    5. write the indexOf method

Test with the driver class: PlayScrabble

  1. 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 be PlayScrabble.
  2. You should see output similar to the depiction in a later section.
  3. 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

  1. Run the unit tests for the project.
    1. right-click on the project int he sidebar of eclipse
    2. choose Run As -> JUnit Test.
  2. you should see that all of the tests pass (in which you already know the score you will get from Gradescope! 💯)

Help

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!
Last modified May 1, 2023: student-sourced updates (1f18b77)