CompSci 6, Fall 2004, Jotto


In the game of Jotto, the player tries to guess a secret five letter word. The game is similar to Mastermind and the game show Lingo in that each guess results in learning how many letters the guess has in common with the secret word. Mastermind is played with colored pegs while Lingo and Jotto are played with words --- though in Jotto the position of letters in common is not important, just the number of letters the secret word and a user's guess have in common.

For this assignment, write a program that lets the user guess a secret word. For each guess the user makes, she should be given feedback about how many letters her guess has in common with the secret word. If she cannot guess the secret word within sixteen tries then she loses. If she guesses the secret word exactly, then she wins. At the start of the game, you should pick a secret word from a file of possible words and remember it throughout the game.

Playing a Game

Here are some runs illustrating how your program might appear to the user. Take this run as a guideline, not a requirement, of how your program should work. User entered input is in italics.

guess #1: fruit
  fruit has 1 letter in common with secret word
guess #2: snake 
  snake has 2 letters in common with secret word
guess #3: piano
  piano has 3 letters in common with secret word
guess #4: sonic 
  sonic has 2 letters in common with secret word
guess #5: panic
  panic has 2 letters in common with secret word
guess #6: snack
  snack has 2 letters in common with secret word
guess #7: manor
  manor has 3 letters in common with secret word
guess #8: slide
  slide has 0 letters in common with secret word
guess #9: guano
  guano has 5 letters in common with secret word
YOU WIN!!!
Here is another example run of the program.
guess #1: brown
  brown has 0 letters in common with secret word
guess #2: plaid
  plaid has 2 letters in common with secret word
guess #3: dowel
  dowel has 1 letter in common with secret word
guess #4: prawn
  prawn is not in the dictionary, try another word
guess #4: brine
  brine has 0 letters in common with secret word
guess #5: fruit
  fruit has 0 letters in common with secret word
guess #6: track
  track has 1 letter in common with secret word
guess #7: ghost
  ghost has 2 letters in common with secret word
guess #8: sharp
  sharp has 2 letters in common with secret word
guess #9: stale
  stale has 3 letters in common with secret word
guess #10: lasts
  lasts has 4 letters in common with secret word
YOU LOSE!!!
The secret word was: glass

The program you write should allow the user to make 16 guesses. If, after sixteen guesses, the word has still not been guessed it should be revealed to the user (for brevity, in the runs shown above the user was only allowed ten guesses; likewise, you may want to use a number lower than 16 when testing). Note, words not in the dictionary should not count towards these 16 guesses and should not be reported back as having letters in common with the secret word.

Comparing the Guess to the Secret Word

To illustrate what happens with a guess, suppose the secret word is "horse". For each of four different guesses, the number of letters in common is shown in the table below.
Jotto Guesses and Responses
guess common letters count
mirth r,h 2
moose o,s,e 3
short s,h,o,r 4
seems s,e 2

Once a particular letter is counted as in common, it cannot be counted again. Note in the table above that "seems" has only two letters in common with "horse". This part of the program is exactly like the lab problem you did last week, so if your version passed all the tests, you should be able to simply reuse the code in this project.

Checking Out the Code

You should start by checking out the project Assignments/01_Jotto using the Ambient menu within Eclipse. The resulting project contains the following files:

Of these files, you will only need to modify the first one, Jotto.java, which models the rules of the game and interacts with the player to get their guesses while they try to guess the computer's secret word as shown in the sample runs above. The other classes have already been completed for you and discussed in class, so you should not need to modify them. Dictionary.java models the possible words the player can guess and chooses one of those words to be a secret word for each game. Scanner.java models a list of delimited data, in this case, a list of words separated by spaces. Prompter.java models your interactions with the player, allowing you to prompt the player to enter data, and then getting their response in a reasonable format for your game.

Finally, the data folder contains several files of words with which you can test your program. Some are small so that you can very quickly verify your program is working correctly and some are very large --- only use these after you are sure your program works for the small ones.

Grading and Submitting

This assignment is worth 20 points.

criteria points goals
Jotto play method 10 works correctly and well written
Jotto commonCount method 4 works correctly and is well written
Jotto constructor 2 works correctly and is well written
README 4 completeness

Submit your project as 01_jotto, using the Ambient menu within Eclipse. Always be sure to submit all java files, even if you did not modify them. You must also submit a README too according to the directions given on the assignment page.