Ask Question
18 September, 01:06

Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this class in future exercises to fully build out a Tic Tac Toe game! The TicTacToe class should have a 2D array as an instance variable and a constructor that initializes the 2D array with the "-" value. Add a getter method that returns the private 2D instance variable.

+1
Answers (1)
  1. 18 September, 04:30
    0
    public class TicTacToe / /Defining TicTacToe class

    {

    char board[3][3]; / /Creating a 2D array instance variable

    TicTacToe () / /Constructor to initialize the array with " - "

    {

    for (int i = 0; i<3; i++) / /Loop for the row of array

    {

    for (int j = 0; j<3; j++) / /Loop for the column of array

    {

    Board[i][j] = '-'; / /Assigning "-" in each cell

    }

    }

    }

    public char getter () / /Defining getter () method to return the array

    {

    return Board; / /returning the array

    }

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Create a TicTacToe class that initializes a 3x3 board of "-" values. We will use this class in future exercises to fully build out a Tic ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers