Question: Please help comment the code: tictactoetester.java package tictactoe; import java.util.Scanner; public class TicTacToeTester { public static void main(String[] args) { Scanner in = new Scanner(System.in);

Please help comment the code:

tictactoetester.java

package tictactoe;

import java.util.Scanner;

public class TicTacToeTester {

public static void main(String[] args) { Scanner in = new Scanner(System.in); String player = "X"; TicTacToe game = new TicTacToe(); boolean done = false; while(!done) { System.out.print(game.toString()); System.out.print("Row for player " + player + " (-1 to exit): "); int row = in.nextInt(); if(row < 0) done = true; else { System.out.print("Column for player " + player + ": "); int column = in.nextInt(); game.set(row, column, player); if(player.equals("X")) player = "O"; else player = "X"; } } System.out.println("Game Over"); } }

TicTacToe.java

package tictactoe;

public class TicTacToe {

public TicTacToe() { board = new String[ROWS][COLUMNS];

for(int i=0; i < ROWS; i++) for(int j=0; j < COLUMNS; j++) board[i][j] = " ";

} public void set(int i, int j, String player) { if(board[i][j].equals(" ")) board[i][j] = player; } public String toString() { String r = ""; for(int i=0; i < ROWS; i++) { r = r + "|"; for(int j=0; j < COLUMNS; j++) r = r + board[i][j]; r = r + "| ";

} return r; }

private String[][] board; private static final int ROWS = 3; private static final int COLUMNS = 3;

}

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!