CSE143

Autumn 2002

Homework 1

The Date Investigators

Overall problem: determine if any interesting anniversaries will occur during this Autumn quarter

Specifically, this time: Given a date, as a string, determine if an interesting anniversary is occuring now.

Electronic deadline: Wedneday, October 16, 2002, 9:00 p.m.

Our focus is almost entirely on programming this time. You'll have a chance to analyze some existing inheritance/interface hierarchies. You'll implement against a given interface, and test your code against some classes we supply. Some of the details about the assignment will be revealed by reading that code and the comments in the code. You'll also need to dig into the Java String class and possibly into the wrapper classes which facilitate conversions between primitive types and strings.


Functional summary description of the finished program: A user starts the program, and has an opportunity to type in a date. The program then shows a report of certain interesting things about that date.

Dates

Dates are assumed to be C.E. (AD) in the usual (Gregorian) calendar. Dates are to be accepted from the use in either of the following formats:

String which don't conform to these models can be considered errors, and should be handled appropriately (read the code for more ideas about this). Your program is free to accept other common date formats, too.

"Interestingness"

A date is "interesting"...

Report all the interesting facts that your investigation discovers. For each interesting fact, report the full original date (in decimal); the number base used for this fact; whether the fact is about years or days; and the number of years or days (both in decimal and in the other number base, if not decimal). Note that the exact format and wording of this report is not specified. (More about this can be deduced from the code. Basically, a "report" will be a single string containing all the needed information).

Internal Requirements

This time there are some fairly strict requirements that your programming must meet, or the program may not even be gradable.

An interface called IDateInvestigator is supplied. You must create a class which implements that interface. Comments in the code will help clarify what the required behavior is. You may not modify IDateInvestigator (you won't be able to turn in a modified version).

A test class with a main is supplied. You can make minor modifications to that code if necessary. For example, replace TrivialInvestigator with the name of your own class. TrivialInvestigator.class is available to place in your project, if you want to run the system before writing your own class. (No, we won't give out source for TrivialInvestigator!) [10/11: New version of TrivialInvestigator.class posted.  Should run with Bluej; also, generates more output in order to test scrolling.  Note that both versions of TrivialInvestigator were compiled with Java 1.4.0; they may not work when combined with class compiled with Java 1.3.]

A graphical user interface for testing is supplied. The main test method will call that GUI. You must use this set of classes, and you may not modify them. (This will be hard for some people, because the GUI is not very pretty or advanced, and you may see good ways to improve. But don't!). You should look at the code for the class, though; more about that later. [10/11: New version of Proj1GUI.java posted.  Corrects a scrolling problem when the output is bigger than the output area.]

I hope we won't have to release updated versions of these classes, but it could happen, so be prepared. [And... it happened!]

Programming Practice (including style)

Last time we just said "use your best style". By this time, you should have a better idea of what your TA and the staff in general consider good programming practice -- follow it as best you can! There's no official style guide in effect, although a good one to refer to is Sun's. We'll be doing more with issues of style and programming practice as the quarter progresses.

You'll be asked at some point to report on how well your program operates, that is, whether it always gets the right answer.

Analytical Exercise

Interfaces and Inheritance are used heavily in the Java libraries. Look through the code in Proj1GUI.java. One way to learn new programming facts and techniques is to read code and consult reference materials. As you know by now, Sun has extensive documentation on the web for the Java libraries (also called APIs, or Application Programming Interfaces).

Draw the "family tree" (inheritance hierarchy) of the user-defined class TextListener. That is, draw a box for TextListener (at the bottom of the page). Draw a box or boxes one level up for each class or interface extended or implemented by TextListener, and draw appropriate arrows connecting them. Then continue the process upward. Go all the way to the top. You don't have to put anything in the boxes except class names, but use something to distinguish interfaces from classes (often interface names are written <<like this>>).

Then do the same for JTextArea. Use a big piece of paper! If it gets totally out of hand, you can stop before it's complete -- as long as you get the idea (and we get the idea that you get the idea!).

You can make these pictures freehand. It is not necessary to use a drawing program or even to worry too much about exact rectangles -- as long as the picture communicates the structure clearly.

Put your name and section on each piece of paper, and staple them together. Hand them in at the beginning of lecture, Friday, October 18.

When reading the JavaDoc, be careful to distinguish between the inheritance hierarchy and the package hierarchy -- they aren't necessarily related.

A Few More Notes

You may work with a partner on all parts of the assignment.  Please use a different partner than you had on Project 0. Detailed instructions for how to turn in your work will be available eventually.

You are free to use any standard Java library class or method. You shouldn't use code from outside the course, but if you do, recognize that with a comment in the code.

Click here to submit electronically (when the form is available. Do NOT use the Project 0 form!)