CSC 172
Homework 2
Assigned Sept. 20, due Sept. 27, to be done in two-person teams
-
Before you start, fill out a Product Plan Estimate form in the
PSP package (click on "Input" under "Product Plan Estimates").
-
As you go, or when you're done, fill out a time log form in the
PSP package (click on "Input" under "Time Management Data").
-
Every time you find and fix a defect, record it
using the PSP package (click on "Input" under "Defect Removal
Data").
-
For this and all your programming assignments, follow the appropriate
design recipe(s).
Among other things, each method should be documented with examples and
the results they should produce (write these before writing the
code!); be sure to test the method thoroughly before turning it in.
-
Each class, method, and variable should have a well-chosen, meaningful
name.
-
Each class should have a static void test() method where you
put all your standard test cases relevant to this class.
-
All javadoc comments (and all comments, for that matter) should
be correct and up-to-date; a misleading comment is worse than none at
all.
-
Write class definitions for three classes:
Circle, Square, and Rectangle. All three
should be part of the same BlueJ package.
Each of your classes should contain
- appropriate instance variables (you'll need to consider the
methods listed below to decide what information is necessary). Note:
you may want to use the Posn class given out in lecture to
represent (x,y) coordinate pairs.
- at least one constructor,
- an area method that takes no parameters and returns the
area of the shape,
- a perimeter method that takes no parameters and returns
the perimeter of the shape,
- a size method that takes no parameters and returns one of
the three Strings "large", "medium",
or "small" depending on whether the area is over 100,
over 10 but no more than 100, or at most 10 respectively,
- a contains method that takes a Posn and returns a
boolean indicating whether the specified point is inside the shape,
- a toString method that returns information about the shape
in a user-friendly format, and
- an equals method that returns a boolean indicating whether
this Circle is the same as a specified other Circle (and likewise for
Squares and Rectangles). You are not required to compare
Squares with Circles, Circles with Rectangles, etc. (we'll learn a good
way to handle this shortly).
- a (static) test method that creates a well-chosen
collection of examples of the class and tests each of the methods on them.
Note: To do computations on circles, you'll need the
mathematical constant "pi", to which you can refer in Java by the name
Math.PI. Be sure to spell it exactly that way: the word
"Math" starts with a capital letter, and both letters of
"PI" are capitalized.
How to turn this in:
When you create a new package in BlueJ, say "hw2", it actually creates a
Windows folder with that name. The easiest thing for me is if you ZIP
the entire contents of that folder into one ZIP file and send me that
ZIP file as an attachment; that way I can just un-ZIP it and be looking
at exactly the same files you had.
Last modified:
Stephen Bloch / sbloch@adelphi.edu