This assignment must be completed by 1:45 PM on 29 October, and uploaded to the Homework 9 moodle page. You should upload only your ColorfulRectangle.java and TesterHW9.java files.
In this assignment you will create a new class using inheritence. This is another small example that you should be able do complete within a couple of hours.
Start by creating a Java application where the main class is called
TesterHW9 and resides in the
Next download a copy of
RotatedRectangle class and add it to your project.
RotatedRectangle is very close to being a solution for
Homework 7 but has been modified
doubles rather than
ints to store
x, y, width, and height values for the rectangle.
This was done to make it a little simpler to interface the
This class also contains the
that was written in lab on 10 October.
Define a new class
by introducing operations for storing a color for the rectangle.
I realize that it might be more natural to use aggregation rather than
inheritance, but we do need an inheritance exercise during the semester.
Represent the color of the rectangle with a single 32-bit integer. This isn’t near as sophisticated as Java’s Color class, but it’s similar to the way color is represented in both the Processing programming language and graphic accelerator cards.
To effectively do this, you need to add a new field for the stored
color and implement appropriate accessor and mutator methods
and a new
public int getColor() ; public void setColor(int) ; public String toString() ;
You also need some constructors. We’re going to have six in all.
Add four constructors similar to the those developed for
None of these four will require more than two Java
statements in the body. Be sure to initialize the color
in all of these constructors.
Add a constructor that can be used to initialize all six internal fields in the following order, x, y, width, height, rotation and color. And finally, implement a copy constructor.
Add a few lines of code in the
DriverHW9 to construct objects with
all six of your constructors and to test your
toString method to print the contents