CSE 373 Spring 2005
Homework #2
Spell Checker (II)
April 8, 2005
Due:
electronically Thursday, April 14, 8:00 pm; paperwork at beginning of
class Friday.
Objectives
- Get some exposure to the graphics and file capabilities of Java.
- Work within a more complex arrangement of packages and files.
- Use the Java Collections framework in the data structures for solving a
problem.
Learn how to use the JUnit test framework.
Description
In this exercise
you will expand on your previous solution to display and spell-check a document. As usual, you will have to
write certain test and driver code, as well as preparing a short report on your
results. In addition (and not related to the programming), work out the
answers to some pencil-and-paper questions.
The main differences compared to the previous version, from a user viewpoint, are:
- The display is done in a graphics window instead of on the console.
Both the document and the spelling dictionary are visible. The lines
of the document should not spill over the edges of the display panel
(similar to what the old .print() method did). [Getting a long
document to scroll vertically is a different problem -- don't panic over it
-- there are hints in the code.]
- Each misspelled word is in some way highlighted or indicated in the
document display. How you do this is up to you.
- The document can be opened from a file. When this happens, the
document dictionary display should be updated.
- The words of the spelling dictionary can be taken from a file. When
this happens, the spelling dictionary display should be updated.
Most of the specification details can be gleaned by studying the code
and comments in the starter code provided. Read the comments carefully, as some things have changed.
The code is divided now between three packages. As before,
implement classes MySpellChecker and TestSpeller
TestSpellChecker (put them in package
WordPro2Speller) and MyDocument and TestDocument (in WordPro2Document); note the constructors have
changed, and there is no starter code for them. Also complete the
implementation of DocumentViewer and
SpellerViewer. WordProStarter contains the main method. You will find other required code mentioned in the files and
elsewhere in this write-up.
Among the files you will find a large spelling dictionary, linuxwords.txt. Your
program should be able to handle this file.
Do not panic about reading in data from files! There is a handy method in
the FileUtilities373 class which should make it fairly painless. You are
not required to use that method if you know another way.
Just as before (and always): You must use the
exact names for classes and methods as specified here and in those
files. You cannot declare a constructor except the one mentioned in
the interface comments. You cannot create additional .java files.
You may not modify any interfaces in this or other assignments (you can't turn
in modified versions). None
of your methods should require any user input of any kind, or any data files
(this will change in later versions of the program). You can have additional helper methods as needed;
ordinarily these should be private. You can define
additional classes but only if they are internal to the specified .java
files.
Last time I didn't feel it needed to be mentioned, but this time let me
stress that one does not declare non-public public instance variables except in quite
exceptional circumstances (such as static finals, i.e., true constants).
If you feel you need any public data, you had better talk to me or the TAs so we
can talk you out of it.
You only need very simple graphics for this project. If you haven't
worked with Java's Swing/AWT components's before, this will give you a chance to
get familiar with them. As with so many things, there is a basic structure
that has to be understood, and it is not necessarily intuitive. Some of
the starter code files contain the basic structure, along with comments to help
you understand it if this is your first time using Swing.
As before (and always): For this and any other assignment in CSE373, you are free to use any standard
Java library class, and to use any method of those classes (unless there is some
explicit instruction to the contrary). Getting familiar with the
standard Java libraries is an essential skill for today's Java programmers.
You should not use any library,
class, or code aside from this (for example, something you found on the Internet
or written by someone outside the class).
For this particular assignment, each student should work alone, without
seeing each other's code. In some
future projects we may pair you up to work together.
You may have used JUnit in the past. Although this assignment involves
writing a test method, you won't use JUnit for it (you will in a later
assignment). Instead, expand and improve the classes TestSpeller
TestSpellChecker and
TestDocument. In particular, make the main method of TestSpeller
TestSpellChecker as
complete and thorough a test of the Speller as possible. It should be able
to detect if there is any error in any implementation of ISpellChecker,
not just yours. TestDocument should also be expanded, but it won't be
weighted as much in the grading.
Getting Started:
- If you didn't have homework 1 working, get it working!
- Download the homework 2 files and make sure you have them set up in the proper
directories.
- Browse through them and make a note of which classes/methods you need to
implement or modify and
which ones you should not modify.
- Try compiling everything. The interfaces should compile right
away. If not, something is not set up properly. Caution: if you
are reusing files from homework 1, note that the package declarations must
change. Be careful that the compiler does not try to use classes from
the old package. If you get a weird message like "assert is a
keyword", it means your IDE is not set up to recognize the assert
keyword, which was new in Java 1.4. Figure out how to tell the IDE you
want it to recognize assert.
- Write JUST ENOUGH of MySpeller and MyDocument to get them to
compile. In other words, create stubs. Same with SpellerViewer
and DocumentViewer.
- Try running the program (the main method is in WordProStarter). You
should see the window, with a picture (if you are on-line) and text in the
panels.
- Work on getting the (default) document and spelling dictionary to display
in the panels. Don't worry at first over highlighting the misspelled
words.
- Continue working... Take advantage of the Message Board when you get stuck
or can't figure out all these complicated instructions. Work on the
pencil and paper problems early (they might help you prepare for quizzes
before the homework is due.)
Pencil and Paper Homework:
From the textbook: Ch. 3, problems R-3.2, R-3.3, R-3.6 (use induction to
prove the answer), R-3.8, and this problem:
Give an example of each of these situations (the answer should be
non-trivial, i.e., not the empty set), or explain why the situation is
impossible:
- a relation which is reflexive, not transitive, and not symmetric.
- a relation which is transitive and not reflexive.
- a function of the integers (i.e., the domain is all the integers, and the
range is (a subset of) the integers) which is reflexive.
- a function of the integers which is transitive and not reflexive.
Your answers may be handwritten as long as they are legible.
Turn in:
Electronically: seven .java files: . Click here to turn in. Recommendation: turn in early and often!
On paper: a printed copy of the "receipt" from your turn-in, which
automatically includes printouts of the .java files. Plus the
pencil-and-paper answer, plus: a short report
which
- describes your algorithms briefly, in English.
- tells whether methods work correctly,
and why you feel that way. If you know of particular things which do not
work, you should list them.
- a brief discussion of how efficient isSpelledCorrectly is.
Compare your current implementation with the one you did in homework 1. You do not have to be very
formal, but should use the terminology for algorithm analysis being
discussed in class.
Grading
Most of the grading points will come from
- Correctness of the algorithms
- Accuracy of the TestSpellChecker (remember, it must be able to test anyone's
version of MySpellChecker)
- Efficiency and elegance of the solution
- Following instructions and specifications
- Programming practice (style, comments, etc.). See link on the 373
home page to the Sun Coding Conventions.
- The report
Good luck and have fun!
Notes
If you have questions along the way, either about the assignment or how
to do things, feel free to discuss it on the Message Board (when it is
operational!). Just
don't give away code, or any crucial aspects of the solution. It is
perfectly OK to share insights about using the Java libraries.
Where applicable, write your code to be reusable and modifiable.
In a later homework, you might in fact have an opportunity to reuse or
modify code from this one...