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)
}
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.
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.
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:
"Give up" (this should reveal
the secret word).To facilitate our unit testing, please provide the following methods
inside object Jotto:
def hasProperForm(word: String): BooleanisLegalWord(word: String): BooleancountMatchingLetters(word1: String, word2: String): IntprovenLetters(secretWord: String, words: List[String]):
Set[Char]disprovenLetters(secretWord: String, words: List[String]):
Set[Char]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
}
}
Zip your Java project and your Scala project together, and turn the zip file in to Canvas. Due by 11:59pm Wednesday, November 9.