CIT 590 Assignment 10: Flash Cards II
Spring 2009, David Matuszek
In Assignment 2 you wrote a Flash Cards program in Python. This will be similar (not identical), but done in Java with Swing GUIs.
In this assignment there will be two classes with a main method, and each of those classes will implement a separate GUI. The user wishing to study will start from one of the "main" classes; the user wishing to create or edit a study list will start from the other.
Terminology: The stimulus is what is presented to the user; the response is what the user is expected to provide. These are more general terms than "question" and "answer." I am using item to refer to the contents of a single flash card, that is, the stimulus together with the desired response.
When the user is trying to study, here's what should happen:
The user can quit the program at any time. There should be a button or menu item provided for this purpose; in addition, simply closing the GUI window should quit the program.
At the beginning of a study session, the data is read in from a file. Each
item on the file consists of: the stimulus, a double bar (||),
and the response. For example (English-Japanese):
I want || hoshii desu
I don't want || hoshiku arimasen
now || ima
yes (casual) || ee
at my place || watashi no tokoro de
at your place || anata no tokoro de
you are skilled || jozu desu
I am not skilled. || Jozu ja arimasen.
The program then randomly chooses, from the input data file, a fairly small number
of items to use (15 or 20; make this number a single final variable)
and ignores the rest. This is so you can have a study list of a thousand items, and the user does not have to learn all 1000 at once. However, if there are fewer items than desired on the input file, use as many as there are.
Each stimulus and each response should be trimmed, using string.trim(), so that the student
does not have to "learn" which words have leading and/or trailing spaces.
In addition to helping the student study, the program should help the teacher build lists of paired items. The GUI should display the items and provide four basic operations on the list:
klein||small and klein||little. If this happens, you have to ask the user
what to do.Plus, of course, you will need to be able to read in the study list, and write out the modified study list.
The GUI classes, which handle interaction
with the user, must do no, repeat no,
manipulation of the data in any way. All they do is handle events and call
methods in the StudyList class. As far as the GUIs are concerned,
they have no idea what their buttons, text fields, and other widgets
are being used for.
There are two GUI classes, StudyGui and ListEditorGui.
Each has a main method.
What the program does depends on which class the program is started from.
The model classes, Item and StudyList,
do all the computational work (in this case, all the file I/O and list manipulation).
They do not access the GUIs in any way. In fact,
if the GUIs were removed from the project, this would not result in any syntax
errors in these classes.
The StudyList class also acts as an
intermediary in any file I/O--if a GUI wants a file loaded or saved, it asks
StudyList to do that. StudyList does not interact with the user; if, while writing the StudyList class, you feel the need to interact with the user, one way is to throw an Exception, and let the GUI class catch it and do the interaction.
Exceptions should not cause program termination.
class StudyGui
Load command to read in a file. (But it just calls a comparable method in the StudyList object.) StudyList object) to the user. Quit command. class ListEditorGui
Load, Save,
and Save As... files.StudyList object and allows them to be edited. Add, Find, Edit,
and Delete items.class Item
Each Item represents one stimulus/response pair. Each Item should have a way of viewing and changing
its stimulus and response parts (getter and setter methods should be good enough
for this).
class StudyList
The StudyList class does no printing or GUI work--it just
keeps track of data. Data consists of all the Items from
the file, and an array of those items (maybe 15 or 20) currently being studied.
Each member of your team should do one of the GUIs, and to specify (with the
@author tag in the class) who did each GUI. Both of you should
work together on the model classes. Your grade will be based 50% on your part
and 50% on the whole thing.
This is a team programming assignment. It's not quite a pair programming project, because each of you is responsible for part of the code, and both of you are responsible for part of it. However, the program has to work. Programs that don't work are worth zero points. So in order to get credit for your GUI--not only the layout, but also the work the model does--the program as a whole has to work.
Since the StudyList contains some methods that will mostly be
used by the StudyGui and others that will mostly be used by the
ListEditorGui, you might want to divide up the work along these
lines.
I recommend that you spend the lab period deciding who does what parts, and making a very specific outline of class responsibilities: constructors, method names, and parameters. Work together as much as you can, including helping each other with GUIs as necessary.
If for some reason you do not have a partner for this assignment, omit the ListEditorGui. You can construct test files in your favorite text editor.
FlashCards: flashCards class StudyGui extends JFrame
public static void main(String[] args) class ListEditorGui extends JFrame
public static void main(String[] args)
class Item
Item(String stimulus, String response) // constructorpublic
String getStimulus()public void putStimulus(String stimulus)public String getResponse()public void putResponse(String response) class StudyList
public void add(Item item)public Item find(String stimulusOrResponse)public void delete(Item item)public void modify(Item item, String newStimulus,
String newResponse)
public void load()
throws IOException
load method in SimpleIO, and
catches any Exceptions that are thrown.public void save()
throws IOException
save method in SimpleIO, and
catches any Exceptions that are thrown. public void saveAs()
throws IOException
saveAs method in SimpleIO, and
catches any Exceptions that are thrown.class SimpleIO (provided)
public static ArrayList<String> load() throws IOException
ArrayList<String> of those lines. It is your job to break
each line up int a stimulus and a response. The method
line.split(" *\\|\\| *") will
break line into an array of those two Strings. public static void save(ArrayList<String> lines)
throws IOExceptionpublic static void saveAs(ArrayList<String> lines) throws
IOException Item and StudyList. FlashCards_yourName_partnersName The above are requirements. You may have additional classes and methods as needed, and they should be documented and unit tested as appropriate.
Thursday, December 3, before midnight, via Blackboard. Please submit one zip file containing all necessary files.