Modify part1 assuming that now you have a bucket of lego blocks with various col
ID: 3777001 • Letter: M
Question
Modify part1 assuming that now you have a bucket of lego blocks with various colors. Write a newclass Legos2 n the same package for this part Use an array of Color objects and initialize the array with the colors: Color red, Color. blue, Color. yellow, Color green, Color .pink, Color black, Color. magenta, Color orange and Color. cyan. For picking the next color for the block, use a java.util.Randomobject and generate a random integer using the nextlnt method. Use the length ofthe colors array as an argument (do not hard code the array length).Explanation / Answer
public class Legos2 extends JFrame {
Color[] colors;
colors = new Color[9];
colors[0] = new Color(Color.red);
colors[1] = new Color(Color.blue);
colors[2] = new Color(Color.yellow);
colors[3] = new Color(Color.green);
colors[4] = new Color(Color.pink);
colors[5] = new Color(Color.black);
colors[6] = new Color(Color.magenta);
colors[7] = new Color(Color.orange);
colors[8] = new Color(Color.cyan);
// Constructor
public Legos2() {
Random reand= new Random();
float r =rand.nextFloat();
float g =rand.nextFloat();
float b =rand.nextFloat();
Color randomColor = new Color(r,g,b)
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.