CIT 594 Flash Card Merge (Scala → Java)
Spring 2015, David Matuszek
The idea of a flash card program is that each "card" has a stimulus on one side and a response on the other. The program chooses and presents a stimulus, and the user is supposed to type in the corresponding response. The program then tells the user if the response was correct. The program decides when and how often to present each stimulus, until it decides that the information on the card has been adequately learned.
Each stimulus must be unique. If two cards were to have the same stimulus, the user could never know which response to give.
Each card is implemented by an Item object. An Item has six fields: The stimulus, the response, and four integers (timesCorrect, timesIncorrect, interval, and date), which hold information about how well the item has been learned, and when it should be presented again. This information is kept on a text file, which I call a "vocabulary list".
One good way to start learning Scala is to translate an existing Scala program into Java. I've been writing a Scala program that seems almost perfect for this purpose, as it uses many of the features unique to Scala. The purpose of the program is to merge two vocabulary lists into one.
Every line on a vocabulary list file has one of two forms:
stimulus || response || integer || integer || integer || integeror
stimulus || response
The latter form is used for "virgin" items, that is, those that the user has not yet seen.
Here's what the program does:
"// " to the line and using it as a stimulus, and using "?" as a response.Your task is to translate the Scala program into Java. Your program should produce exactly the same results as the Scala program. The translation can be "loose" (replacing the Scala idioms with Java idioms), but do your best to translate the program, using the same methods and the same logic. Do not just write a new program from scratch that does the same thing.
If you have any questions about what the Scala program does, run it to find out.
You will need either Scala by itself, or (recommended) the Scala IDE, which is built on top of Eclipse.
My program makes use of scala.swing, which is based on javax.swing. Java now has JavaFX, and Scala is moving to ScalaFX, but in the meantime scala.swing has gotten a bit hard to find. For that reason I'm providing scala-swing.jar, which you can install just as you would any other jar file.
The code which you are to translate consists of two files, Item.scala and ListPreparer.scala, both of which should be put in a listPreparation package. If there are any discrepencies between what the code does and what this page says it does, believe the code. You can read a code listing with notes, which should help explain what the code is doing.
To get started testing, you can use tinyGermanFile.txt and tinyGermanFile2.txt. You should probably add to these files.
You do not need to provide JUnit tests, or comment the code more thoroughly than I have done.