/**
 * CS149 - Introduction to Programming
 * Department of Computer Science
 * James Madison University
 * @version Fall 2018
 */

PA5 - 00000111 Little Words (Classes)

Due Dates and Submission Details

See submission details below for all due dates and submission details. Note there are multiple submission parts.

Honor Code

This assignment should be completed individually to maximize learning. It is important that you adhere to the Course Policies, particularly the section on Programming Assignments. Also relevant is the JMU Honor Code.

Objectives

Background

00000111 Little Words is a single-player game. The player's objective is to guess the seven words that correspond to the seven provided clues. There is no time limit and there is no penalty for incorrect guesses.

Information Provided to the Player

The player is provided with seven clues and the length of the corresponding word/answer. In addition, the player is provided with a group of tiles, each of which contains a slice of one of the words to be guessed.

Guessing

To make a guess, the player selects tiles (in order) and then presses the Guess button. When a tile is selected it is temporarily removed from the board.

After a correct guess, the tiles that constituted the guess are permanently removed from the board. After an incorrect guess, the tiles that constituted the guess are returned to the board (i.e., made available for another guess).

Hints

At any point, the player can request (with no penalty) a hint for a particular clue. Specifically, the player can ask for the first letter in the word associated with the clue, the first tile in the word associated with the clue, or the answer.

Shuffling

At any point, the player can shuffle the available tiles (which may help the player see patterns that weren't visible before).

Game Creation

Games are created by an author, not the player. To create a game, the author creates a single text file that contains seven dash-delimited records/lines. The first field in each record/line contains the answer, and the second contains the clue.

Note that the author does not create the tiles, the program creates them from the words using a slicing algorithm.

An outside author created three game files that you can use for testing.

Computer Science Terms
JMU People
Nets

Of course, you can easily create more.

Requirements

The system that you must implement is summarized in the following UML class diagram.
SystemDesign2.png

You are responsible for implementing the classes in black. The .class files for the classes in blue are available from the following links.

GameBoard
Tile
GuessField
FileUtilities
FileUtilities.java
Note this latter source code is being provided as there are a few people that are having issues with getting the FileUtilities class to show up. Please be aware that this may not solve all of your problems when you submit to AutoLab and even more important do not submit this file or the corresponding class file with your submission. If you change this file your code will not be compatible with AutoLab.

The first three are part of the graphical user interface (GUI), the last is a utility class for reading files. Note that you do not need to (and should not) use the Tile and GuessField classes directly, they are used by the GameBoard class. The purpose of the methods in the other classes should be apparent from their names.

The Main Class

The main class for this assignment is SevenLittleWords. It must:
  1. Construct a GameInfo object using the file name passed to it as command-line argument 0. If no such argument is provided, it must print an appropriate error message on the console and terminate.
  2. Construct a GameBoard using the GameInfo object. If the GameInfo object isn't read properly/completely, it must instead print an appropriate error message on the console and terminate.
  3. Show the GameBoard object by calling its setVisible() method and passing it the value true.

The Slice Class

A Slice is a two-letter or three-letter portion of a word.

A Slice can either be in the used state or the unused state. When a Slice is in the unused state its toString() must return its text. However, when it is in the used state it must return the empty String (i.e., "").

It must be possible to put a Slice in the used state by calling its use() method. On the other hand, it must be possible to put it into the unused state by calling its reset() method. Its isUsed() method must return true when it is in the used state and false otherwise.

The WordUtilities Class

The only public method in the WordUtilities class is slice(). It must create the slices for the word it is passed in a manner that is consistent with the following specifications.
  1. All the letters in a slice must be uppercase characters.
  2. When the length of the word (in characters) is evenly divisible by three, each slice must contain exactly three characters.
  3. When the length of the word (in characters) is instead evenly divisible by two, each slice must contain exactly two characters.
  4. When the length of the word (in characters) is neither evenly divisible by three nor evenly divisible by two, slice 0 must contain exactly three characters and all other slices must contain exactly two characters.

For example, the word "Madison" has the slices "MAD", "IS", and "ON".

The array that is returned by this method must contain the appropriate number of slices, no more and no fewer.

Note that, though the game has the modifier "little" in its name, this method must work correctly for any parameter that has two or more characters.

The WordClue Class

A WordClue is a pair that contains a word along with its associated clue and slices.

The constructor must initialize all of the attributes in the obvious way, with two exceptions. When the word passed to the constructor is null or has fewer than MIN_WORD_LENGTH characters, the corresponding attribute must be set to "DEFAULT". Similarly, when the clue passed to the constructor is null, or has no characters, or has more than MAX_CLUE_LENGTH characters, the corresponding attribute must be set to "DEFAULT CLUE".

All of the methods that return a hint must return a String that contains nothing but uppercase characters. (Hint: Look in the String class for a method or methods that might be helpful.) On the other hand, the getClue() and getWord() methods must return the corresponding attribute "as is".

Each of the toString() methods must return a String representation of the WordClue. The version that is passed a boolean parameter named verbose behaves differently depending on the value of verbose. When verbose is false the String it returns must consist of a single "line" (terminated by a '\n' character) that contains the word, followed by a dash (i.e., a '-' character), followed by the clue. For example, toString(false) for the WordClue constructed from "madison" and "the university's namesake" must return madison-the university's namesake\n.

On the other hand, when verbose is true the String it returns must consist of two "lines" (each terminated by a '\n' character). The first "line" must be the same as when verbose is false, and the second "line" must contain the slices, with a space between each pair. For example, toString(true) for the WordClue constructed from "madison" and "the university's namesake" must return madison-the university's namesake\nMAD IS ON\n.

Finally, the toString() method that has no parameters must return the verbose String representation.

The equals() method must return true when the word attribute of the two WordClue objects contain the same characters, ignoring their case. (Hint: Look in the String class for a method or methods that might be helpful.)

The GameInfo Class

The GameInfo class is an encapsulation of all of the information needed to play a game, including the information provided by the author of the game (stored in a WordClue[]) and the calculated information (stored in a Slice[]).

The constructor must read the information (provided by the author of the game) from the given file (using the FileUtilities class), construct a WordClue object from each line, and construct all of the Slice objects for all of the words.

The isComplete() method must return true if the appropriate number of words/clues were read and must return false otherwise.

The toString() method must return a String that consists of multiple "lines" (each terminated with a '\n' character) satisfying the following specifications.

For example, the toString() method must return the following String for the game in net.txt (where each "line" is on its own line).

Cluelist
browser-it helps you surf the net
bullock-The Net actress Sandra
fault-result of serve into the net
brooklyn-Nets home, in the NBA
acrobat-performer with a safety net
gross-net pay before withholdings
imprecise-like one casting a wide net

Slices
BRO
WS
ER
BUL
LO
CK
FAU
LT
BR
OO
KL
YN
ACR
OB
AT
GRO
SS
IMP
REC
ISE

Submission

You must submit a .zip file named pa5.zip that contains GameInfo.java, SevenLittleWords.java, Slice.java, WordClue.java, and WordUtilities.java.

Your submission will be graded using the following criteria:

Note that the style criterion is mandatory for this assignment. This means that neither the correctness nor the quality of your code will be assessed if it does not conform to the style guide. Hence, if your code does not conform to the style guide you will receive a grade of 0 for Part B.

Note also that the correctness of some classes depends on the correctness of the others (e.g., WordClue uses WordUtilities and Slice, GameInfo uses WordClue and Slice). So, it is important that you get the "foundational" classes working correctly.

Advice

You should write and test one class at a time, and, within each class, you should write and test only a few methods at a time.

Probably the best way to proceed is as follows.

  1. Write the Slice class.
  2. Test the use(), reset() and isUsed() methods.
  3. Test the toString() method.
  4. Write the WordUtilities class.
  5. Test the slice() method in the WordUtilities class on String objects of length 3, 4, 6, 8, and 11.
  6. Write the constructor, getClue(), and getWord() methods of the WordClue class.
  7. Test those methods.
  8. Write the equals() method.
  9. Test the equals() method.
  10. Write the other "getters" in the WordClue class.
  11. Test the other "getters" in the WordClue class.
  12. Write the other toString() method in the WordClue class.
  13. Test the other toString() method in the WordClue class.
  14. Write the constructor and isComplete() method of the GameInfo class.
  15. Test the constructor and isComplete() method of the GameInfo class.
  16. Write the "getters" in the GameInfo class.
  17. Test the "getters" in the GameInfo class.
  18. Write the toString() method in the GameInfo class.
  19. Test the toString() method in the GameInfo class.
  20. Write SevenLittleWords class.
  21. Test the complete product.