Assignment 3 Design

 

Due date:                Tuesday 3/9/04 by 4:00pm

Hand in electronically:               Nothing

Hand in printed copies:               Volunteer.java, TrashCan.java, Trash.java, ParkCleanup.java

(comment skeletons only, not code) and your keyHit() algorithm and implementation plan

 

Assignment 3 is split into two parts.  The first part is an object-oriented design, which I’ll look at and give you feedback on, to make sure you’re on the right track before you start coding.  The second part is the actual code.  The assignment is described in the usual place, with one page for the assignment as a whole and a separate page with official design instructions.

 

IMPORTANT NOTE: I want you to do something different for the design part than what the official version says.  So you should ignore the official design instructions and follow these instead.  You still need to read the instructions for the assignment as a whole.

 

Design instructions:

 

1)               You will be designing four classes.  Volunteer, TrashCan, and Trash are instantiable classes.  ParkCleanup is an instantiable main class.  What I want from you is four Java files with only Javadoc comments, data member declarations, and method headers in them.  It’ll be like a skeleton of your eventual code.  As an example, here’s what you would do for the Die class:

 

public class Die {

 

        /** The number of sides the die has. */

        private int numSides;

 

        /** The side currently facing up. */

        private int sideUp;

 

        /**

         * Constructor: initializes data members.

         * @param sides The number of sides the die will have

         */

        public Die (int sides) {}

 

        /**

         * Method to roll the die and return the result.

         * @return The side that came up on top

         */

        public int roll() {}

}

 

As you can see, there’s no actual coding or debugging involved here, but there is a good deal of planning.  You’ll need to choose what data members go inside each class.  You’ll also need to plan exactly what each method will do, what parameters it will take, and what it will return.  Include both the methods they say are required and other methods that your classes will need (there should be some extras in each class).  Remember to include the main method in ParkCleanup.

Please note that your design is allowed to change once you start coding—you’re not forever stuck with what you come up with here!  But make this design as complete as possible, really thinking about how all the parts will interact with each other, and you will really save yourself a lot of time.  Look at the way the RobotRally program was designed, and at the design examples we’ve done in class, for guidance on how to design this one.


Addition: part 1.5: The keyHit() method in ParkCleanup will be the one that really runs the simulation. Once you've set up the game, by creating a ParkCleanup object in the main method, the only thing your program does is respond to user input. When the user hits a key, the keyHit() method will automatically get called, and you decide what to do based on the key. Outline the algorithm (set of steps) that your keyHit() method will follow, using a list of steps or pseudocode. Think of it in terms of these things: how it decides what to do with the input character, how it updates the status of the ParkCleanup object so that the getStatus() method will work properly (hint: store a String into a data member each time the user does something), and what it does if the time is up or the game is over.



 

2)               Once you’ve done the comment skeletons, do an implementation plan:  a set of steps that you’re going to follow when you start coding.  It should be incremental.  This means doing a small part, testing it, doing another small part, testing it, etc.  Here’s an example for the Die program.  (Yours will obviously be longer, since you have more than one class in your program.)

 

0)     Add simple, meaningless return statements to all methods that have non-void return types, just to get the program to compile.  (For example, put  return 0; in the roll method above.)

1)     Write any methods involved in making a Die object, and construct one in the main class to test them.

2)     Write any methods involved with rolling, and roll the Die object to test them.

3)     Write the user input/output methods in the main class, and complete the program by using them.

 

 

Assignment 3 Code

 

Due date:                Friday 3/26/04 by 4:00pm

 

Hand in electronically:               Volunteer.java, TrashCan.java, Trash.java, ParkCleanup.java

                                    questions.txt

 

Hand in printed copies:               Volunteer.java, TrashCan.java, Trash.java, ParkCleanup.java

 

 

When you get your design back from me, you may have to edit it somewhat.  Once it’s in good shape, you can start coding.  You can add things as you go that were not in your design, and you can change things, too.  Don’t wait until a couple days before the deadline to start coding this—it will take you longer than you think.  Do make use of your design and implementation plan when you start coding—otherwise what was the use of doing them?

 

And finally, a motivational quote:

 

"A program is either so simple that it obviously has no errors, or so complex that it has no obvious errors."

 

In this program, as in every program, we will be aiming for the first option. :-)