Hi There!

I'm Dan Schlegel, an Associate Professor in the Computer Science Department at SUNY Oswego

Programming Challenge 6: The Snow Family

In this assignment you will model two classes – snow people and snow families, allowing you to practice your class modeling, good programming techniques, and your use of constructs like ArrayLists.

Why do it?

This assignment glues together nearly everything we’ve done this semester, and will provide excellent practice for the final exam!

The SnowPerson Class

  1. Create a new Java class called SnowPerson in the snowpeople package.
  2. Create the instance variables and constructor for SnowPerson based on the fact that snow people have a name, a height, and a number of buttons. Think about what types make sense to use for those. Remember that the purpose of a constructor is to initialize the instance variables.
  3. Add a toString method to your SnowPerson class which returns a string with the snow person’s name, height, and number of buttons formatted in a nice way.
  4. Remember that classes are developed, not written, so create a Java main class file to test your SnowPerson class. We’ll be adding some painting mechanisms to the SnowPerson class in a minute, so you might want to use the skeleton at the bottom of this page.
  5. We now wish to paint our snow people. Add another instance variable to your SnowPerson class for the color used, and initialize it with a random color at the appropriate point in your code.
  6. Add a method called paint to your SnowPerson class which takes as an argument an SPainter. In this method, paint your snow person. Make use of (at least) the defined height. You may use only circles for drawing the snow person. Use your imagination – yours doesn’t have to look like mine! Be sure to use good practices as far as problem decomposition and invariance.
  7. Test your SnowPerson class by enhancing your tests from before. You’ll need to make an SPainter to pass to the SnowPerson‘s paint method. Iterate on your design until you are happy with it.

The SnowFamily Class

  1. Create a class called SnowFamily in your snowpeople package.
  2. Your class should have a single instance variable – an ArrayList of snow people.
  3. Your constructor will take one argument, the number of people in the snow family. The goal of your constructor will be to initialize the ArrayList instance variable as a new empty list, and to populate it with snow people according to user input.
  4. Use the techniques we’ve used before this semester to create popup windows to ask the user for the information required to make the snow people, and add them to the ArrayList. Be sure you make as many as specified by the argument to the constructor!
  5. Add a toString method which returns a string containing the details of each snow person in the family. You should make use of the SnowPerson‘s toString method.
  6. As before, create a tester class to make sure your class is working as it should.
  7. Add a method, called paint, to the SnowFamily class. It will take one argument, an SPainter. This method should make calls to the paint method in each of the snow people stored in the ArrayList. Paint each family member side-by-side.
  8. Test your SnowFamily class by enhancing your tests from before. You’ll need to make an SPainter to pass to the SnowFamily‘s paint method. If it doesn’t work as you expect, go back and fix it!

The Testing Skeleton

The Exit

  1. The assignment is due November 29th.
  2. The last day to demo will be December 2nd, the last day of classes. It must be demoed on or before December 2nd.
  3. You must post your work to you work site and demo to a TA to receive credit.
  4. Reflect on this assignment, your solution, and their relationships with the course content. Think on your engagement with the assignment and the course.