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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started