Ask Question
16 November, 00:59

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.

+4
Answers (1)
  1. 16 November, 01:16
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers