Invoking methods on a Board object

 

Cells in a Board object have color and textual attributes associated with them that can be accessed by invoking any one of its several methods.  The first method we’ll consider is called turnOn, which changes the color of a cell to black.  To be useful, methods often require that we send them one or more values as input (don’t confuse the usage of the term input here with user input from keyboard).  Values sent to a method are called parameters.  The method turnOn takes for parameters two values, the x and y coordinate of the cell that we wish to color black.  Using the object reference grid, we can turn on the corners of the board using the four statements (in clockwise order starting with origin):

 

     

grid.turnOn(0, 0);

grid.turnOn(4, 0);

grid.turnOn(4, 2);

grid.turnOn(0, 2);

The Board object should now look like what’s to the left.