Question: DO NOT add new import statements. DO NOT change any of the method s signatures. You will work on the ColorGameWQU.java class, and implement its

DO NOT add new import statements.
DO NOT change any of the methods signatures.
You will work on the ColorGameWQU.java class, and implement its constructor.
The constructor is simply a method, which is only called when a new object of that class type is created.
i.e "ClassName temp = new ClassName()" calls the public ClassName() constructor. This constructor is expected to initialize class attributes and do any other work that is needed for the "temp" variable to be used.
Constructors can take in parameters, just like a method. You can also create multiple constructors for a single class, with different parameters in each. You do not need to create any additional constructors for this lab.
For example, the constructor for the "Integer" (the wrapper class for int) has two constructors. The first takes in an int and sets the Integers value to that. And the second takes in a String, converts it to an int, and then sets the Integers value to that.
You are provided with a completed Coordinate.java class, which represents a single (row, col) coordinate. When using 2D arrays, a Coordinate at (4,3) would be array[4][3]. On an XY Grid, this would be equivalent to (3,4)(since row represents height, and col represents width)
To complete the ColorGameWQU constructor:
1) First instantiate the "parent" and "size" arrays. These are already declared for you as class attributes (aka fields).
To access and modify these class attributes, use "this.parent" and "this.size". While the "this." prefix is not always required, it is good practice to always use it when referring to class attributes
Set both arrays equal to a new array of their corresponding array types:
The "parent" 2D array is of type "Coordinate[][]"
The "size" 2D array is of type "int[][]", it is NOT "Integer[][]"
The size of both arrays is [row][col], which is given by the constructor parameters
2) Finally, set the default values for both arrays:
You can accomplish this using only a double for-loop (nested), since the height (number of rows) and width (number of cols) of the two arrays are the same.
For each index in the arrays:
Set the parent array at that index equal to a new Coordinate. Pass in the (row,col) values to the Coordinate constructor. This sets the parent of each cell to be itself by default.
Set the size array at that same index equal to 1, since it is its own parent.
Once you have initialized the class attribute arrays, and set their default values, the Color Memorization Game should be functional when you compile and run the ColorGameWQU class.

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 Programming Questions!