Menu
support@authoritypapers.com
+1(805) 568 7317

there are a few errors that i can 39 t seem to fix please help me so that the progra 3602097

There are a few errors that I can't seem to fix.

Please help me so that the program compiles and executes correctly without any errors.

Thank you.

public class TicTacToe {

private final int BOARDSIZE = 3;

private final int WIN = 1, DRAW = 2, CONTINUE = 3;

private int board[][];

private boolean firstPlayer, gameOver;

public TicTacToe()

{

board = new int[ BOARDSIZE ][ BOARDSIZE ];

firstPlayer = true;

gameOver = false;

}

// start game

public void makeMove()

{

int row = 0, column = 0;

while ( !gameOver ) {

// first player's turn

if ( firstPlayer ) {

row = Integer.parseInt( JOptionPane.showInputDialog(

“Player 1: Enter row ( 0

column = Integer.parseInt( JOptionPane.showInputDialog(

“Player 1: Enter column ( 0

// validate move

while ( !validMove( row, column ) ) {

row = Integer.parseInt( JOptionPane.showInputDialog(

“Player 1: Enter row ( 0

column = Integer.parseInt( JOptionPane.showInputDialog(

“Player 1: Enter column ( 0

}

firstPlayer = false;

board[ row ][ column ] = 1;

printBoard();

printStatus( 1 );

} // end first player's turn

// second player's turn

else {

row = Integer.parseInt( JOptionPane.showInputDialog(

“Player 2: Enter row ( 0

column = Integer.parseInt( JOptionPane.showInputDialog(

“Player 2: Enter column ( 0

// validate move

while ( !validMove( row, column ) ) {

row = Integer.parseInt( JOptionPane.showInputDialog(

“Player 2: Enter row ( 0

column = Integer.parseInt( JOptionPane.showInputDialog(

“Player 2: Enter column ( 0

}

firstPlayer = true;

board[ row ][ column ] = 2;

printBoard();

printStatus( 2 );

} // end seond player's turn

} // end while

} // end method makeMove

// show game status in status bar

public void printStatus( int player )

{

int status = gameStatus();

// check game status

switch ( status ) {

case WIN:

System.out.println( “Player ” + player + ” wins.” );

gameOver = true;

break;

case DRAW:

System.out.println( “Game is a draw.” );

gameOver = true;

break;

case CONTINUE:

if ( player == 1 )

System.out.println( “Player 2's turn.” );

else

System.out.println( “Player 1's turn.” );

break;

} // end switch

} // end method printStatus

// get game status

public int gameStatus()

{

int a;

// check for a win on diagonals

if ( board[ 0 ][ 0 ] != 0 &&board[ 0 ][ 0 ] == board[ 1 ][ 1 ] &&

board[ 0 ][ 0 ] == board[ 2 ][ 2 ] )

return WIN;

else if ( board[ 2 ][ 0 ] != 0 &&board[ 2 ][ 0 ] ==

board[ 1 ][ 1 ] &&board[ 2 ][ 0 ] == board[ 0 ][ 2 ] )

return WIN;

// check for win in rows

for ( a = 0; a

if ( board[ a ][ 0 ] != 0 &&board[ a ][ 0 ] ==

board[ a ][ 1 ] &&board[ a ][ 0 ] == board[ a ][ 2 ] )

return WIN;

// check for win in columns

for ( a = 0; a

if ( board[ 0 ][ a ] != 0 &&board[ 0 ][ a ] ==

board[ 1 ][ a ] &&board[ 0 ][ a ] == board[ 2 ][ a ] )

return WIN;

// check for a completed game

for ( int r = 0; r

for ( int c = 0; c

if ( board[ r ][ c ] == 0 )

return CONTINUE; // game is not finished

return DRAW; // game is a draw

} // end method gameStatus

// display board

public void printBoard()

{

System.out.println( “_________________________” );

for ( int row = 0; row

System.out.println( “| | | |” );

for ( int column = 0; column

printSymbol( column, board[ row ][ column ] );

System.out.println( “|_______|_______|_______|” );

}

} // end method printBoard

// print moves

public void printSymbol( int column, int player )

{

String output = “”;

if ( column != 2 ) { // first two columns

switch ( player ) {

case 0:

output = “| “;

break;

case 1:

output = “| 1 “;

break;

case 2:

output = “| 2 “;

break;

}

}

else { // last column

switch ( player ) {

case 0:

output = “| |n”;

break;

case 1:

output = “| 1 |n”;

break;

case 2:

output = “| 2 |n”;

break;

}

}

System.out.print( output );

} // end method printSymbol

// validate move

public boolean validMove( int row, int column )

{

return row >= 0 &&row < 3 &&column >= 0 &&column

board[ row ][ column ] == 0;

}

// main method

public static void main( String[] args )

{

TicTacToe game = new TicTacToe();

game.printBoard();

System.out.println( “Player 1&#39;s turn.” );

game.makeMove();

System.exit( 0 );

}

} // end class TicTacToe

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now