Question: **Need help debugging this java code. my output is somehow not matching. public class TicTacToe { private int turn; private char[][] board; public TicTacToe() {

**Need help debugging this java code. my output is somehow not matching.

public class TicTacToe { private int turn; private char[][] board;

public TicTacToe() { turn = 1; board = new char[3][3]; }

public int getTurn() { return turn; }

public void printBoard() { System.out.println(" 0 1 2"); for (int i = 0; i

public boolean pickLocation(int row, int col) { if ((row >= 0 && row = 0 && col

public void takeTurn(int row, int col) { if (pickLocation(row, col)) { if (getTurn() % 2 == 0) { board[row][col] = 'O'; } else { //System.out.println(" "); board[row][col] = 'X'; } turn++; } }

public boolean checkRow() { for (int i = 0; i

public boolean checkCol() { for (int j = 0; j

public boolean checkDiag() { if (board[0][0] == 'X' || board[0][0] == 'O') { if ((board[0][0] == board[1][1]) && (board[1][1] == board[2][2])) { return true; } } if (board[0][2] == 'X' || board[0][2] == 'O') { if ((board[0][2] == board[1][1]) && (board[1][1] == board[2][0])) { return true; } } return false; }

public boolean checkWin() { if (checkRow() || checkCol() || checkDiag()) { return true; } return false; } }

**Need help debugging this java code. my output is somehow not matching.public class TicTacToe { private int turn; private char[][] board; public TicTacToe(){ turn = 1; board = new char[3][3]; } public int getTurn()

public class TicTacToeTester public static void main(String[] args) //This is to help you test your methods. Feel free to add code at the end to check //to see if your checkwin method works! TicTacToe game = new TicTacToe(); System.out.println("Initial Game Board: "); game.printBoard; //Prints the first row of turns taken for(int row = 0; row

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