CIT 590 Previous Announcements
Spring 2009, David Matuszek

Date Announcements
May 6, 2009 The following have been posted: DavesSudokuModelTest.java and DavesTranslatorTest.java.
April 21, 2009

Correction: The findBestMatch method is mentioned twice in the Makeup Assignment, but with different signatures. The correct signature is static long findBestMatch(String badNumber).

Also, please note that the createDatabase(int size, long seed) method should be called from the NumberChecker(int size, long seed) constructor. To do otherwise is to risk all my JUnit tests failing, which would result in a very low grade.

Finally, this assignment asks you to use assert statements. Remember that assert statements are ignored unless you tell Java to enable them. See the Eclipse FAQ for instructions on how to enable assertions.

April 16, 2009

Because some people are not getting the expected '\012' in their text areas for newlines, I'm providing another Translator, ShowHex.java, which you can use to find out what characters really are in your text area. It will display the hexadecimal (not octal) codes for each character, plus a two- or three-letter abbreviation for the nonprinting characters (Cr for carriage return, Lf for linefeed, etc.). To use this Translator, just add it to your project (you may have to add a package declaration to it), and add the line
     addTranslateItem(new ShowHex());
to your Translator class.

April 14, 2009

In lab, I was uncertain whether text areas would automatically become scrollable when you added enough text to them.

The answer is, java.awt.TextAreas do, but javax.swing.JTextAreas don't.

To make a JTextArea behave like a TextArea, just put it inside a JScrollPane, and use the JScrollPane where you would have used the JTextArea. Like this:

    myPanel.add(new JScrollPane(myTextArea), BorderLayout.CENTER);
April 9, 2009 I've posted some of my code, for Hammurabi.java, ArrayOperations.java, and ArrayOperationsTest.java. I will post some additional solutions when I have time.
April 7, 2009 I was wrong sad face and Jiwei was right happy face; JTextField has no TextListener. In lieu of that, here's the best I've been able to come up with:
/**
 * Adds a KeyListener to a text field.
 * @param textField The text field.
 * @param row The row in which the text field occurs.
 * @param column The column in which the text field occurs.
 */
 private void addListener(JTextField textField, final int row, final int column) {
    textField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            checkValidity(row, column, e.getKeyChar());
        }
    });
}
One important point is that the key that was typed is not actually added to the text field until after the listener finishes, so it is necessary to use e.getKeyChar() rather than textField.getText(). My checkValidity method, after it determines whether the character is valid, sets the background color of the text field.
April 7, 2009 For those of you who would like to replace a grade on a previous assignment (most likely, but not necessarily, the Traffic assignment), I've now posted a totally optional Makeup assignment.
March 27, 2009 I've already made some corrections to the Paired Associate Learning assignment (highlighted in bright green). I've also make the load, save, and saveAs methods in SimpleIO public (Thanks, Avi!), and added a link (below, and here) to SwingExamples.jar.
March 17, 2009 Midterm Exam Grades
Midterm Exam Grades

Average (mean), 66.56

Median, 70

St. dev., 16.54

March 3, 2009 Here is a page describing all the Java O-O concepts (including some we haven't gotten to yet). This may help you in your studying for the midterm exam.
March 1, 2009 There was an error in the written description of the reshape method (the picture was correct, though).
February 23, 2009 Today (Monday), Abdul's office hours will be from 5 pm to 6 pm.
February 23, 2009 I've posted my version of the CokeMachine program. I've tried to use only Java constructs that I had already talked about--no methods, no do-while loops, etc.
February 20, 2009

Abdul's office hours for next week:
      Monday 3.30 pm - 4.30 pm
     Wednesday 3.30 pm - 4.30 pm

February 20, 2009 The due date for the Traffic assignment is now Sunday, before midnight.
February 17, 2009

Suppose a Car class describes a car, and a Town object describes a town.

  • Does a town contain a lot of vehicles, or does a car contain a lot of vehicles? (Hint: Use your common sense here.)
  • Should a Town object contain an array of vehicles, or should a Car object contain an array of vehicles? (Hint: Refer to your answer to the previous question.)
  • When you are displaying an array of vehicles, are you looking at a Car, or at a Town?
  • When you are driving across town, do you buy a new car at every intersection, or do you just change the location of the car you are in?
  • In the "real world," do cars create other cars?

Your program will be a lot easier to write if you use your knowledge of the world to decide which classes should have which variables, and what objects of each class should be able to do. Also, there is usually a "main" class--Town, in this case--which is responsible for "global" events, such as new cars being created, and displaying results.


Also, people have been asking about paint and repaint. Here's the short, easy answer: You write the paint method for cars and for ambulances, but you call my repaint method (my repaint method (in ArrayDisplay) will call your paint method for each of your Vehicles). Again: You write the paint methods, but you call my repaint method.


Here is an example program that uses ArrayDisplay. Copy this zip file to your workspace and unzip it; then from within Eclipse, File -> Import... it.

February 12, 2009 I forgot to mention this in class--and Bridge players already know this--but Aces outrank any other cards. Hence the ordering is 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack(11), Queen(12), King(13), Ace(1).
February 1, 2009 In class we have discussed while loops, do-while loops, and for loops. Here is another kind of loop.
January 30, 2009 Here are some Style Rules you should follow.
January 28, 2009 I have posted some Required Eclipse settings. Please use these settings for all future assignments (the third assignment and beyond).