In an earlier assignment, Artist, you created an animation which included several animals. At that time, you relied on the use of the class, Group, to manipulate your animal as a single coherent unit, rather than as a scattered collection of individual shapes. We saw several advantages in that representation of an animal, such as being able to easily move the animal in the scene.
That use of the class Group was a step in the right direction, but this time we would like to go a step further, having you create, and document, a new class which represents your specific animal.
For this assignment, you must work individually in regard to the design and implementation of your project. Please make sure you adhere to the policies on academic integrity.
For the sake of discussion, let's suppose that my original Artist submission has generated an animation which included several monkeys. Presumably my code for the Artist.run() method included some 15-20 lines of code specifically for modeling the monkey. I probably instantiated various shapes to represent the arms, legs and tail of the monkey, as well as instantiating a new Group to represent the monkey as a whole. Then the body parts were added to the group, and the group was added to the canvas.
Suppose that I were proud of my representation of a monkey and that I wanted to add more monkeys into my scene, or better yet, I wanted to allow other people to conveniently add my monkeys into their own animations. I might accomplish this by simply making the 15-20 lines of code which I had used available to others, verbatim, for inclusion in other places. But a much better design, in the spirit of object-oriented programming, would be to define a new class, say Monkey containing the necessary code. Then, others could use this new class with minimal effort, just as they had used the more primitive shapes. For example, an artist might simply specify:
Monkey chimp = new Monkey();
chimp.move(80,120);
canvas.add(chimp);
This is our goal. Of course, there is no reason to reinvent the wheel; we do not wish to create our new class entirely from scratch. We have already seen that the concept of a Group is a great model for representing a Monkey, and so we will use inheritance to define a Monkey as a subclass of Group. Therefore, we might start out our class definition using syntax such as:
import csa120.shape.*; // so that we can use classes Group, Circle, Rectangle, etc
public class Monkey extends Group
{
...
}
In this way, any object from class Monkey inherits all of the instance variables and methods associated with the class Group, such as move(), draw(), setDepth() and so on. Of course, if we do not add any additional code to the class definition for Monkey, then our class will be identical to that of a Group. Presumably, new instance variables and behaviors may be added, and existing behaviors might be specialized.
In this assignment description, we have been using the discussion of a class Monkey purely for example. Your project should involve the development of a new class to represent your own choice of animal, most likely an animal used in your original Artist project.
Please adhere strictly to the following minimum requirements for the development of such a class:
You will need to write a constructor which appropriately initializes a newly created animal. Presumably, this will involve the creation and placement of several underlying shapes, which are then added to the animal using the inherited method add().
You may decide whether or not to allow additional parameters when calling the constructor which effect the initial settings for your animal.
All monkeys are not alike! The point of such a class is not simply to make precise clones of an animal, but to allow reasonable variance as well. For example, I might allow a user to change the eye color of a monkey, the tail thickness, the positioning of the arms, the direction of the face.
Specifically, you must define at least three new (and distinct) methods which are appropriate for customizing your chosen animal.
To accomplish the above tasks, you will probably need to introduce additional instance variables for the class that were not present in the parent class. If you do so, please delcare all such variables to be either private or protected, so that they cannot be directly manipulated by a user of such an object.
For someone else to know how to use your class, you must provide sufficient documentation. For this, we would like you to use javadoc comments as described in lecture and the associated notes. If creating a new class in BlueJ, the given templates may provide helpful guidance. Also, please see our lecture notes for Java Documentation.
Specifically, please ensure that:
You provide a javadoc comment immediately before the beginning of the class definition, which gives an overview of the class as a whole.
Any instance variable which you add to the class should be described in a javadoc comment immediately preceding the variable declaration.
Any method which you create should be proceded by an appropriate javadoc comment, given an overview of the behavior, as well as explicit descriptions of any parameters or return values.
Here, the goal is to show hwo your class could be used by another. Your animation for this assignment does not need to correspond to the precise animation you created in the original Artist assignment. However, we would like your new animation to satisfy the following requirements:
Demonstrate the use of each new method introduced in your class.
Display at least four distinct animals from your new class, making sure that the properties vary among those animals.
We have placed a copy of the template files for this assignment, Animal, in each of your home directories on patel2.slu.edu.
As was the case with the earlier assignment, we start you with two classes in the project:
Artist
You should express your animation by completing the
run() method of this class.
ArtistDriver
This is a file which you should not edit. It is the main driver
to execute your program.
The assignment is worth 10 points. The grades for this assignment will not be based on artistic merit, rather on your success in meeting the explicit requirements discussed in this assignment statement.
Create a new behavior, rescale(double scale), which changes the size of your animal by "multiplying" it by the given scale. You can assume that scale>0, but you should make sure to handle values both above and below 1.
Presumably, this behavior would resize all of the lower level components which comprise your animal, but you will also need to take into consideration whether some of those components need to be moved relative to each other, to keep in tact the spirit of your figure.
One additional complication will be that the underlying shape coordinates and size are expressed using integer coordinates, and here we are allowing you to scale by non-integral values.