Question: For this in-class lab, we will create an array of objects and then iterate through each object, using the display() method to display each rectangle

For this in-class lab, we will create an array of objects and then iterate through each object, using the display() method to display each rectangle in a different location on the screen (and with different colors!)

Use the starter code below to get you going please fill out the commented areas with the necessary code in Java:

public class Rectangle {

private int x, y, w, h, r, g ,b;

public Rectangle(int x, int y, int w, int h, int r, int g, int b) {

this.x = x; this.y = y; this.w = w; this.h = h; this.r = r; this.g = g; this.b = b;

}

public void display() {

fill(r, g, b); rect(x, y, w, h);

}

}

void setup() {

size(600,600);

//create an array of Rectangle objects

//use a for loop to instantiate each spot as a Rectangle object

//randomize their positions and colors

}

void draw() {

//access the display() method for each Rectangle using a for loop

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!