Question: please fix the code / / arley suazo import java.util.Scanner; public class TicTacToe { private char [ ] [ ] board; private char turn; private
please fix the code
arley suazo
import java.util.Scanner;
public class TicTacToe
private char board;
private char turn;
private String winner;
private Scanner input;
public TicTacToe
board new char;
turn X;
winner "None";
input new ScannerSystemin;
Initialize the board with empty cells
for int i ; i ; i
for int j ; j ; j
boardij;
public void printBoard
System.out.println;
for int i ; i ; i
System.out.print;
for int j ; j ; j
System.out.printboardij;
System.out.println
;
private boolean validMoveint row, int col
return row && row && col && col && boardrowcol;
private void getNextMove
int row, col;
while true
System.out.printlnPlayer turn : Enter row or : ;
row input.nextInt;
System.out.printlnPlayer turn : Enter column or : ;
col input.nextInt;
if validMoverow col
boardrowcol turn;
break;
else
System.out.printlnInvalid move. Please try again.";
private String gameStatus
Check rows and columns for a win
for int i ; i ; i
if boardi turn && boardi turn && boardi turn return String.valueOfturn;
if boardi turn && boardi turn && boardi turn return String.valueOfturn;
Check diagonals for a win
if board turn && board turn && board turn return String.valueOfturn;
if board turn && board turn && board turn return String.valueOfturn;
Check for draw
boolean isDraw true;
for int i ; i ; i
for int j ; j ; j
if boardij
isDraw false;
break;
return isDraw "Draw" : "Continue";
public void play
while true
printBoard;
getNextMove;
String status gameStatus;
if status.equalsContinue
winner status;
printBoard;
if winnerequalsDraw
System.out.printlnThe game is a draw.";
else
System.out.printlnPlayer winner wins!";
break;
Switch turns
turn turn XO : X;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
