CIS 554 Assignment: Solo Jotto
Fall 2016, David Matuszek

Purposes of this assignment

Part I (10 points)

Translate the following Scala program into Java.

import scala.io.StdIn.readLine

object Buzzer extends App {
  val n = readLine("How high shall I count? ") toInt

  for (i <- 1 to n)
    if (i % 7 == 0 || i.toString.contains('7')) println( "buzz")
    else println(i)
}

Part II (80 points)

General idea

The computer chooses a secret 5-letter word with no repeated letters. The user then guesses 5-letter words (again, with no repeated letters). For each word guessed, the computer tells the user how many letters in the guessed word are also in the secret word, but gives no information about where they are in the secret word. Play continues until the user guesses the secret word, or gives up.

Optional: The computer should give the user help by keeping track of which letters have been proven to be in, or not in, the secret word.

For a nice version of this program, see http://jotto.augiehill.com/single.jsp. Your version will be simpler (text only instead of GUI, no choices like easy/hard or word length, etc.), but should essentially behave the same way.

Files and programming hints

Download and save the word list at http://www-01.sil.org/linguistics/wordlists/english/wordlist/wordsEn.txt.

When your program starts, it should read in this word list, discarding all words that are not exactly five letters long, or that have repeated letters. Words containing an apostrophe or other non-letters should also be discarded. Hint: Use the filter method, possibly more than once.

My Concise Introduction to Scala provides a simple way to read in a file as a list of Strings.

The Random class is in scala.util. See the Scala API for details.

Details

You should have a project named Jotto, containing a package named jotto in the src folder, containing files Jotto.scala and JottoTest.scala. The program in Jotto.scala should consist of a single object, object Jotto {...}, containing a main(args: Array[String]) method.

The program should:

To facilitate our unit testing, please provide the following methods inside object Jotto:

def hasProperForm(word: String): Boolean
Tests whether the "word" consists of exactly five letters, all distinct.
isLegalWord(word: String): Boolean
Tests whether the word occurs in the program's list of legal words.
countMatchingLetters(word1: String, word2: String): Int
Determines how many letters the two words have in common.
Methods that will be unit tested should not perform any I/O.

The following methods are optional:
provenLetters(secretWord: String, words: List[String]): Set[Char]
Determines which letters must be in the secret word, based on the words guessed so far.
disprovenLetters(secretWord: String, words: List[String]): Set[Char]
Determines which letters must not be in the secret word, based on the words guessed so far.
Implementing the optional features, and using them to assist the user, will be worth an additional 10 points.

Unit testing (10 points)

Write, in a file JottoTest.scala , unit tests for all your non-I/O methods.

In Eclipse, go to Project → Properties → Java Build Path → Add External JARs and select your ScalaTest jar. Here is a model for your test file.

package fractionTest

import org.scalatest.FunSuite
import Fraction._

class ExampleTests extends FunSuite {
  
  val f1 = Fraction(1, 2)
  val f2 = Fraction(1, 4)
  
  test("Test multiplication") {
    assert(f1 * f1 == f2)
  }
  
  test("Test bad multiplication") {
    assert(f1 * f2 === f2) // "===" may be used in unit tests
  }
}

Due date

Zip your Java project and your Scala project together, and turn the zip file in to Canvas. Due by 11:59pm Wednesday, November 9.