CS 117 Winter 2006 Lab 6
Program Development


Part of the goal of this assignment is to give you more practice with Java and with some program design. So I encourage you to consider working on this project alone, but you're also welcome to work with your assigned partner. Be sure to put your names at the top of your Snowplow.java! Create a directory lab6, and put your answers there. Submit what you have finished at the end of the class period! I will take a look at submissions when I get back into town, and then set a due date (not before Wednesday) for the completed lab. (Of course, feel free to keep working on this lab before an official due date is announced.)

Tasks for the day:

  1. Look to the northeast. Send a curse in that direction, from whence the nor'easter that stranded DLN in Boston originated.

  2. Your main task: download Snowplow.java and fill in all of the missing methods and all of the unimplemented functionality. All of the methods that you're supposed to fill in (and all of the functionality that you're supposed to add) are specifically mentioned in the code. Also write a tester class to demonstrate that your code works properly.

    Concentrate on readability in your code! (A significant portion of your grade for this lab will be based on your code's readability.) Things that are important to consider: indentation (and staying under 80 characters per line), descriptive variable names, comments that explain what each method does, comments that explain the goal of "meaningful" segments of code, comments that explain how any particularly tricky lines work, splitting off functionality of any particularly complicated methods into separate methods, and so forth. There's a style guide posted; you should try to follow it. If you have any questions about style, please ask Paul or David!

  3. Add "odometer" functionality to your Snowplow class. That is, a snowplow should keep track of the number of road segments that it has traversed since it was created. You should also add an appropriate accessor method
        public int getDistance()
    to your class.

  4. Add a method
        public int plowAll()
    to your Snowplow.java. Using the functionality that you added in Question 2 that allowed your snowplow to drive around the streets, write a method that will plow all of the streets. The specification is this: you must start with the snowplow at the depot (the parameters to the constructor). You must finish with all of the streets plowed (so allPlowed() must return true), and the final position of the snowplow must be the same as the original (depot) position. The return value of this method must be the distance traveled by the snowplow.

    Extra credit will be given to the group or groups whose Snowplow works correctly and covers the smallest distance in doing so. (I'll choose the grid size and the starting location, and you may assume that I'll do so in the way that is most inconvenient for you.) Take some time to think through the most efficient way to traverse the grid!


By David Liben-Nowell.