Modify part1 assuming that now you have a bucket of lego blo

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).

Solution

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)
  
}

}

 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 C

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site