CSC 171
Homework 7

Assigned April 15, due April 27

Design Recipe

For each programming problem below, you should follow the same 6-step recipe as in previous assignments:

  1. Contracts

  2. Write test cases

  3. Write the Java code. This step can be broken down into

    1. write a skeleton.

    2. if you're writing a method, write down a list of available ingredients

    3. fill in the details

  4. Proofread the code.

  5. Compile the code.

  6. Test the code.

PSP logging

For this assignment, I want you to record not only the defects you encounter, but also a "product plan estimate" and how much time you actually spend in various stages of writing the program. You can do all this very conveniently using the on-line PSP forms.

For the "product plan estimate", click the "Input" button under "Product Plan Estimates" in PSP. Fill in the program number (e.g. "hw7"), and your educated guesses as to how long the program will be (in lines), how long it will take you (in hours and minutes), and how many defects you'll encounter. Be sure to do this before you start writing any code -- ideally, even before you do most of the design. Note that your entry is date-stamped, so I can tell if you enter your estimate the night before the program is due.

To record your time, click the "Input" button under "Time Management Data" in PSP. Fill in the program number (e.g. "hw7"; this should match what you said in the estimate), the date that you spent the time, how many hours and minutes you spent, and what stage of development you were working on. (For definitions of stages of development, click the link Development Stage.)

After you've finished your program, you can have the computer count how long it really is by clicking "Count lines in your program." You'll need to do this once for each class you wrote, e.g. if you used my file World.java, and wrote your own subclass in MyWorld.java that used other classes in Foo.java and Bar.java, you would do this once each for MyWorld.java, Foo.java, and Bar.java. After you've done this, you can "Compare estimates with reality" to see how your estimates (for size, time, and defects) compare with what actually happened.

Note that you will not be graded on how accurate your guesses are (unless they're really wacky, like 100000 lines finished in an hour with no defects). Make the best guess you can, and your guesses on subsequent projects will get steadily better.

Warm-up exercise

I've written a World class to replace MouseApplet, so you can work either in BlueJ or in DrJava, and you can use Loggers, assert, and the debugger effectively.

Make a copy of one of the BlueJ projects you did for homework 6. Download the file World.java and add it to this project. Change your SampleMouseApplet class so that instead of extending MouseApplet, it extends World. Remove MouseApplet from the project and re-compile; it should still compile without errors. To run it, instead of choosing "Run Applet..." from the menu, simply choose "new SampleMouseApplet()"; it should run pretty much the same as it did before (except perhaps for the menu bar at the top of the window).

Programming assignment

Since we've done chapter 7 on designing programs, I'm going to be much less specific this time; you need to figure out for yourself what classes, what variables, and what methods to write, what versions to go through in what order, how to test them all, etc. I recommend writing a subclass of World, above, but if you prefer, you may write a subclass of MouseApplet instead.

Write a graphical program that draws three different-sized faces on the screen, in random locations. Each face consists of an outer circle, two filled-in eyes, a straight-line mouth, and a name (either "a", "b", or "c") where the nose should be. After the faces are drawn, the user should be able to click the mouse anywhere in the window; the program will respond to a mouse-click by asking the user which face to move ("a", "b", or "c") and what color its eyes should be ("blue", "green", "black", or "pink"). The specified face will move from wherever it was to be centered on wherever the mouse was clicked, and the color of its eyes will change as specified.

Be sure to go through the design process -- identifying classes, variables, methods, class relationships, etc. and writing test cases as appropriate -- before writing the code itself. Look for opportunities to re-use classes and methods you've written before: by re-using a bunch of stuff from previous homeworks, I was able to write version 1 of this in about ten minutes. (Version 1 produced the picture above; it doesn't yet respond to mouse clicks, or change eye colors, and the noses aren't quite centered.)


What to turn in

A folder with all the files (especially the .java files!) you needed to solve the above problem. Do an initial estimate of program size, defects, and time in PSP, and subsequently record in PSP what time you actually spend and what defects you actually encounter. You may also want to turn in a separate log in text form, if there are things you want to keep track of that don't fit into the PSP error-logging model, such as design decisions. Be sure contracts (names & types) are specified, either in the source code or in your separate log file; test cases may bein JUnit testing classes, or in the program fileitself, or in a separate log file; for testing user interactions, write a "script" that describes what you'll do, what the computer should do in response, etc.

Grading standards

Estimates       /10
Design       /50
Contracts       /25
Test cases       /25
Java code       /50
Time logs       /10
Defect logs       /30
Total:       /200

Last modified:
Stephen Bloch / sbloch@adelphi.edu