Playing Compiler
Find and correct the syntax and logic error(s) in the following class. Board encapsulates a two-person game. Board uses a two-dimensional array that holds pieces of type
class Board
{
private ArrayList
items; int turn; // which player's turn, 1 or 2
public Board()
// default constructor
{
items =.new
bo[8][8]; turn = 1;
} // creates an empty 8 by 8 two-dimensional array
public Board(int initialCapacity, int player )
// one-argument constructor, creates 2-dim array
// with initialCapacityrows and columns
{
items = new
bo[initialCapacity] [initialCapacity]; turn = player;
}
public Board(int initialRowCapacity, int initialColumnCapacity, int player)
// two-argument constructor, creates 2-dim array with
// initialCapacityrows and columns
{
items = new
bo[initialCapacity] [initialCapacity]; turn = player;
}
public T whoseturn()
// accessor for whose turn it is
{
return (turn);
}
public T addtoBoard(T item, int row, int col)
// lets you put a piece on the board
{
bo[row, col] = item;
}
public T peek(int row, int col)
// lets you peek at a piece on the board
{
return bo[row][col];
}
public void switchturn()
// lets you switch whose turn it is
{
if (turn == 1)
turn = 2;
if (turn == 2)
turn = 1;
}
}
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.