CIT 594 Flash Card Merge (Scala → Java)
Spring 2015, David Matuszek

Purposes of this assignment

General idea of the assignment

The background

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".

The problem

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 || integer
or
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:

  1. Reads in and stores one entire vocabulary list.
  2. Reads in a second vocabulary list.
  3. For each item on the second list,
    1. If an error is encountered, an item is created by prefixing "// " to the line and using it as a stimulus, and using "?" as a response.
    2. If the stimulus is different from any previously read item, the item is just stored as is.
    3. If the stimulus matches that of a previously read item, the user is shown both responses (which could be identical, but probably aren't), and asked to either choose one, or type in a new response. The chosen response is entered into the existing item. The stimulus and integer fields of the existing item are not changed. The redundant (second) item is discarded.
  4. The merged list is saved to a file. The order of items in the vocabulary list is preserved; the order in which they are written out is the order in which the items were read in.

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.

In more detail

Supplied code

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.

Due date

Turn your assignment in to Canvas before 6 a.m. Tuesday, April 14.