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; } }

![public class TicTacToe { private int turn; private char[][] board; public TicTacToe()](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66de5912bb83c_82666de591256e24.jpg)
![{ turn = 1; board = new char[3][3]; } public int getTurn()](https://s3.amazonaws.com/si.experts.images/answers/2024/09/66de591353061_82666de5912e69a9.jpg)
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
Get step-by-step solutions from verified subject matter experts
