CMSC110 (Introduction to Computing)
Fall 2013
Assignment#6
Part 1: Due before start of class on
Monday, November 25, 2013
Part 2: Due before start of class on
Wednesday, December 4, 2013
First, read Chapter 6 from GXK.
This assignment has TWO PARTS. See due dates above for each part. See below for descriptions for each part.
Part 1: Design an underwater creature. The creature should be designed so that it can be instantiated as an object. Make sure you name the class as <YourFirstInitialLastName>Thingy. For example Jia Tao's creature will be JTaoThingy. Deepak Kumar's creature will be defined in a class called DKumarThingy. You should be able to create instances of the creature with varying sizes. In addition to the constructor, make sure that the class includes a method called display() so that one could incorporate your creature in a sketch as follows:
JTaoThingy JTFish; // An instance of JTaoThingy will be called JTFish float SIZE; // The SIZE of the instance that will be created void setup() { size(_, _); smooth(); SIZE = ...; JTFish = new JTaoThingy(SIZE); // Create an instance with size, SIZE ... } // end of setup void draw() { // display the creature JTFish.display(); } // end of draw class JTaoThingy { // Definition of the creature JTaoThingy JTaoThingy(float _size) { ... } void display(...) { ... } // display() ... }// end of class JTaoThingy
The focus should be on the use of classes to define the object factory. You will need to write the constructor, and the operations as described above.
Make sure that your creature is not too small, nor too large, as it will have to live in an aquarium with 40+ other creatures!
Part 2: Next, you will extend the creature's definition. Add a new behavior move() to your creature's class. Depending upon the creature you designed in Part 1, define appropriate move() behavior. Some creatures will swim like a fish, or a submarine, some will wiggle about, some might just stay in one place and rotate, bubble, etc. If the creature is moving about, make sure that it either stays within the bounds of the sketch or emerges at the other end. Strategies for implementing these will be discussed in class. Here is a revised skeletal sketch that will create one instance of the creature and have it show its behavior.
JTaoThingy JTFish; // An instance of JTaoThingy will be called JTFish float SIZE; // The SIZE of the instance that will be created void setup() { size(_, _); smooth(); SIZE = ...; JTFish = new JTaoThingy(SIZE); // Create an instance with size, SIZE ... } // end of setup void draw() { // the creature moves
JTFish.move();
// display the creature JTFish.display(); } // end of draw class JTaoThingy { // Definition of the creature JTaoThingy
JTaoThingy(float _size) { ... } void display(...) { ... } // display()
void move() {
...
} // move() ... }// end of class JTaoThingy
In your overall sketch pay special attention to the aesthetic aspects of your design. Write your own aquarium sketch where you can display several creatures of varying sizes. Make it 800x600 pixels.
What to Hand in: Hand in the entire sketch folder in your Dropbox folder. In addition to the sketch/programs also include; (1) a gif/jpg/png image of your finished sketch. (2) A formatted write-up with Page#1 showing your sketch, followed by a title, your name, a short 1-2 line description (as discussed in class) on page#1, and a short 1-2 paragraph more detailed description of the sketch and your personal experiences working on this sketch.
Back to CMSC110 Course Web Page