Wednesday, February 9, 2011

Today's Do Now:
1. Download the files TicTacToe.java and TicTacToeTester.java from the class website.

2. Add a Method to TicTacToe that counts the number of empty board locations.

Solution :

(Note: The new method must not be typed with in another method)
/**
* What this Method does is it counts the empty board locations, by declaring a new
* variable called count set to equal zero, and as the program advances it moves
* along the empty spaces and increases the value of count as it passes these empty
* spaces but if the space is occupied the value of count stays the same until it
* the method comes across a another empty board space.
*
*/
public int countEmptySpaces()
{
int count = 0
for ( int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLUMNS; col++; }
if (board[row][col].equals(" ")) { count++; }
}
}
return count;
}

No comments:

Post a Comment