Hi There!

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

Programming Challenge 6: Monsters!

In this assignment you will model two classes – monsters and monster hordes, 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 Monster Class

  1. Create a new Java class called Monster in the horde package.
  2. Create the instance variables and constructor for Monster based on the fact that monsters have a name, a size, and a number legs, eyes, or some other physical property (if you aren’t sure if it’s OK, ask us!). You can add additional constraints (an even number of arms?) Think about what data 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 Monster class which returns a string with the monster’s name, size, and number of whatever you chose (labeled nicely).
  4. Remember that classes are developed, not written, so create a Java main class file to test your Monster class. We’ll be adding some painting mechanisms to the Monster 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 monsters. Add another instance variable to your Monster 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 Monster class which takes as an argument an SPainter. In this method, paint your monster. Make use of (at least) the defined size and number of whatever you chose. You may use circles and rectangles for drawing your monsters. Use your imagination – yours doesn’t have to look like ours! Be sure to use good practices as far as problem decomposition and invariance.
  7. Test your Monster class by enhancing your tests from before. You’ll need to make an SPainter to pass to the Monster‘s paint method. Iterate on your design until you are happy with it.

The MonsterHorde Class

  1. Create a class called MonsterHorde in your horde package.
  2. Your class should have a single instance variable – an ArrayList of monsters.
  3. Your constructor will take one argument, the number of monsters in the horde. The goal of your constructor will be to initialize the ArrayList instance variable as a new empty list, and to populate it with monsters 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 monsters, then 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 monster in the horde. You should make use of the Monster‘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 MonsterHorde class. It will take one argument, an SPainter. This method should make calls to the paint method in each of the monsters stored in the ArrayList. Paint each monster side-by-side.
  8. Test your Horde class by enhancing your tests from before. You’ll need to make an SPainter to pass to the MonsterHorde‘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 December 5th.
  2. The last day to demo will be December 8th, the last day of classes. It must be demoed on or before December 8th to receive any credit.
  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.