CSC 171
Homework 2

Assigned Feb. 6, due Feb. 13

Design Recipe

For each programming problem below, you should follow a 6-step recipe:

  1. Choose names and data types as necessary for the problem at hand. Write these down on paper or in a text file.
  2. Write test cases: a sequence of things you plan to type in the Interactions window, and what answer each one should produce, in order to confirm that it works correctly. For now, write these on paper or in an ordinary text file (later on we'll learn slicker ways to test our programs).
  3. Write the Java code in the Definitions Window.
  4. Proofread the code, looking for misspellings, mismatched braces, missing semicolons, etc.
  5. Compile the code. If there are syntax error messages, log them for future reference, fix them, and return to the "Proofread" step above, until there are no error messages.
  6. Test the code by typing into the Interactions window the things you said you were going to try. If any of them produce answers different from what you expected, log what happened for future reference, fix the error, and return to the "Proofread" step above, until everything works the way you expect.

Error logging

I want a log of everything that went wrong in the development of your programs. Ideally, each log entry should include

In practice, sometimes you won't have anything interesting to say about a particular error -- for example, if the error was a misspelling, the "treatment" is presumably to retype the word, and the "prevention" is to type and proofread more carefully next time -- so you can skip that part, and concentrate on the more interesting errors.

Programming assignments

Writing a method

In DrJava, open the Point class I provided on the universal share drive; let's say, version 5. Write an additional method named rightOf that takes in a Point parameter named that, and returns a boolean indicating whether this is to the right of that.

I've given you the answers to step 1: the method is named rightOf, it returns a boolean, and it takes in a Point named that. Write these down and turn them in anyway, along with your test cases and code.

Writing a class

In DrJava, open a new file.

  1. Define a class named Person that contains three pieces of information: firstName, lastName, and age, of appropriate data types.
    Remember to go through the 6-step recipe for this part of the assignment before going on.
  2. Add a toString method to the class, combining the first and last names and the age in a user-friendly manner and returning the result as a String.
    Do the whole 6-step recipe again for this part of the assignment before going on.
  3. Add an olderThan method to the class, taking in another Person and returning a boolean indicating whether this Person is older than the other Person.
    Again, go through the whole 6-step recipe before going on.
  4. Add a constructor method to the class, taking in values for the first name, last name, and age. Same 6-step recipe.

Last-minute change!

Replace the olderThan method with a youngerThan method (or, if you prefer, add the youngerThan method so you've got both). This method should, of course, have its own test cases and all that. Also record how long it takes you to make this modification.

CodeLab:

Do the exercises in the section entitled "CH 2: objects, classes, & methods". These don't have to be finished by Feb. 13, but they'll be most helpful if you do them around the same time as you're doing the rest of this stuff.

What to turn in

Grading standards

Problem Names and types Test cases Java Code Error log
rightOf /5 /5 /10 /5
Person /5 /5 /10 /5
toString /5 /5 /10 /5
olderThan /5 /5 /10 /5
constructor /5 /5 /10 /5
Total: /125

Last modified:
Stephen Bloch / sbloch@adelphi.edu