CSC 171
Homework 8

Assigned April 26, due May 4

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, just as in homework 7. You can do all this very conveniently using the on-line PSP forms.

New and improved World class

I've made some improvements to the World class you used in homework 7. The main problem with the old version was that the top twenty pixels or so were swallowed up by the title bar of the window. So please download and use the new and improved version of World. Before going on, test your homework 6 and/or homework 7 programs on this new version of World, to make sure they still work.

Warning! Several students have reported inexplicable NullPointerExceptions when using this "new and improved" World class in BlueJ on Windows (it works fine on my Macintosh, and it sometimes works in DrJava on Windows.) I haven't yet figured out what's wrong. If you have this problem, you have several choices:

Programming Assignment 8a

Write a class named StringList that stores a bunch of Strings in an ArrayList. In addition to the usual toString() method and constructor(s), it should have methods to add a specified String at a specified position in the list, add a specified String at the end, remove the String at a specified position in the list, search for a specified String (returning its position in the list if found, or a special impossible value if not), and find the longest String in the list.

Programming Assignment 8b

Modify your face program from homework 7 to display an arbitrary number of faces, stored in an ArrayList. Start with three faces, as in homework 7, but we'll also create two "buttons" (Java actually has a built-in Button class, but I don't want to explain how it works yet so we'll do our own): draw a green box somewhere in the window, with the word "new" centered in it, and a red box somewhere else in the window, with the word "delete" centered in it. Whenever the user clicks inside the green box, the program will ask the user for the name of the new face; it will then create a new face, with random location and size and the specified name, and add it to the ArrayList. Whenever the user clicks inside the red box, the program will ask the user for the name of a face to delete; the program will then search through the ArrayList for a matching name, and remove it if found. If the program doesn't find a face with a matching name, it will do nothing. When the user clicks in a place that isn't inside either box, the program will behave as it did before: ask which face to move, and what color to make its eyes, and move the specified face to the mouse location. If the "face to move" isn't found in the ArrayList, the program will do nothing.

(A little friendlier than "do nothing" when the user types an unrecognized face or color name would be to put up a dialog box with a suitable message; you can use JOptionPane.showMessageDialog for this. It takes two parameters; use null for the first parameter, and your error message for the second.)

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.

Essay Assignment 8c

Re-read the adages page, and choose one (or several closely-related) adages, or one longer article, that mean more to you than they did in January.
Write an essay of one or more well-structured paragraphs: what does it really mean in practice? Do you agree or disagree? Support your claims with specific examples from your own programming experience.


What to turn in

Two folders (perhaps zipped), labelled "8a" and "8b" or something like that, each containing all the files you needed to solve the above problem, and a document (plain text, Word, RTF, or HTML formats) containing your essay 8c. For each programming 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

HW8a StringList
 Estimates       /10
 Design       /50
 Contracts       /25
 Test cases       /25
 Java code       /50
 Time logs       /10
 Defect logs       /30
HW8b Faces
 Estimates       /10
 Design       /50
 Contracts       /25
 Test cases       /25
 Java code       /50
 Time logs       /10
 Defect logs       /30
HW8c essay        /50
Total:         /450

Last modified:
Stephen Bloch / sbloch@adelphi.edu