/**
* A simple rectangle object that can be drawn on the screen
*
*/
public class ARectangle {
int x;
// distance from left edge of rectangle
// left edge of screen
int y;
// distance from top edge of rectangle to top
// edge of screen
int width;
// width of the rectangle
int height;
// height of the rectangle
boolean fill;
// True if rectangle is solid
Color color;
// Color of the rectangle
/** construct a new rectangle object
* @param xPosition position of left edge of
rectangle
* @param yPosition position of top edge of rectangle
* @param origWidth width of rectangle
* @param origHeight height of rectangle
*/
public ARectangle(int xPosition, int yPosition,
int origWidth, int origHeight){
this.x = xPosition;
this.y = yPosition;
this.width = origWidth;
this.height =
origHeight;
this.fill = true;
// newly constructed rectangles
// are filled
this.color = Color.white;
// newly constructed rectangles are
// white
/** set size of rectangle
* @param w width of rectangle
* @param h height of rectangle
*/
public void setSize(int w, int h){
this.width = w;
this.height =
h;
}
/** set location of rectangle
* @param newX location of rectangle left edge
* @param newY location of rectangle right edge
*/
public void setLocation(int newX, int newY){
this.x = newX;
this.y = newY;
}
/** set color of rectangle
* @param c new color
*/
public void setColor(Color c){
this.color = c;
}
/** set to fill
*/
public void setToFill(){
this.fill = true;
}
/** set to outline
*/
public void setToOutline(){
this.fill = false;
}
}
Invent a drama that illustrates the following code:
rect = new ARectangle(10, 10, 200, 300);
rect.setToOutline();
rect.setColor(Color.blue);
rect.setSize(400, 100);
You may want to split up the roles as the "director" person, the "object" person, and the "methods" person who gives messages to the "object" person. Props such as cards or pieces of paper with variable names and values might also be helpful.
After spending about 10 minutes creating your drama, we will share these
with the rest of the class.