In this exercise, we are going to complete the Tic Tac Toe game. In the TicTacToeTester class, use the methods that you created in the TicTacToe class to implement your own version of Tic Tac Toe.

Your game should take user input to determine which index the user would like to place their X’s and O’s, and check to see if there is a winner after every turn that is taken. If the user inputs an invalid space, they should be notified, and asked to input another index. Utilize loops to implement this effectively!

Your game should indicate which player won, and notify the users if there is a tie at the end. public class TicTacToe
{
    private String[][] board = new String[3][3];
    private int turn = 0;
    public TicTacToe() 
    {
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[i].length; j++) {
                board[i][j] = "-";
            }
        }
    }
   //this method returns the current turn
   public int getTurn()
   {
       return turn;
   }
   
   /*This method prints out the board array on to the console
   */
   public void printBoard()
   {
         System.out.println("  0 1 2");
        for (int i = 0; i < board.length; i++) {
            System.out.print(i + " ");
            for (int j = 0; j < board[i].length; j++) {
                System.out.print(board[i][j] + " ");
            }
            System.out.println();
        }
   }
   
   //This method returns true if space row, col is a valid space
   public boolean pickLocation(int row, int col)
   {
        if (row >= 0 && row < board.length && col >= 0 && col < board[row].length) {
            return board[row][col].equals("-");
        }
        return false;   
   }
   
   //This method places an X or O at location row,col based on the int turn
   public void takeTurn(int row, int col)
   {
        if (turn % 2 == 0) {
            board[row][col] = "X";
        } else {
            board[row][col] = "O";
        }
        turn++;
   }
   
   //This method returns a boolean that returns true if a row has three X or O's in a row
   public boolean checkRow()
   {
        for (int i = 0; i < board.length; i++) {
            if (!board[i][0].equals("-") && board[i][0].equals(board[i][1]) && board[i][1].equals(board[i][2])) {
                return true;
            }
        }
        return false;   
   }
   
    //This method returns a boolean that returns true if a col has three X or O's
   public boolean checkCol()
   {
       for (int j = 0; j < board[0].length; j++) {
            if (!board[0][j].equals("-") && board[0][j].equals(board[1][j]) && board[1][j].equals(board[2][j])) {
                return true;
            }
        }
        return false;
   }
   
    //This method returns a boolean that returns true if either diagonal has three X or O's
   public boolean checkDiag()
   {
       return ((!board[0][0].equals("-") && board[0][0].equals(board[1][1]) && board[1][1].equals(board[2][2])) || 
                (!board[0][2].equals("-") && board[0][2].equals(board[1][1]) && board[1][1].equals(board[2][0])));   
   }
   
   //This method returns a boolean that checks if someone has won the game
   public boolean checkWin()
   {
       return checkRow() || checkCol() || checkDiag();
   }

}import java.util.Scanner;

public class TicTacToeTester
{
    public static void main(String[] args)
    {
        
    }
}