Ask Question
8 March, 16:23

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.

+2
Answers (1)
  1. 8 March, 17:12
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers