subject

For this exercise, you will complete the TicTacToe Board that we started in the 2D Arrays Lesson. We will add a couple of methods to the TicTacToe class.

To track whose turn it is, we will use a counter turn. This is already declared as a private instance variable.

Create a getTurn method that returns the value of turn.

Other methods to implement:

printBoard()- This method should print the TicTacToe array onto the console. The board should include numbers that can help the user figure out which row and which column they are viewing at any given time. Sample output for this would be:

0 1 2
0 - - -
1 - - -
2 - - -
pickLocation(int row, int col)- This method returns a boolean value that determines if the spot a user picks to put their piece is valid. A valid space is one where the row and column are within the size of the board, and there are no X or O values currently present.
takeTurn(int row, int col)- This method adds an X or O to the array at position row, col depending on whose turn it is. If it’s an even turn, X should be added to the array, if it’s odd, O should be added. It also adds one to the value of turn.
checkWin()- This method returns a boolean that determines if a user has won the game. This method uses three methods to make that check:

checkCol- This checks if a player has three X or O values in a single column, and returns true if that’s the case.
checkRow - This checks if a player has three X or O values in a single row.
checkDiag - This checks if a player has three X or O values diagonally.
checkWin() only returns true if one of these three checks is true.

public class TicTacToeTester
{
public static void main(String[] args)
{
//This is to help you test your methods. Feel free to add code at the end to check
//to see if your checkWin method works!
TicTacToe game = new TicTacToe();
System. out. println("Initial Game Board:");
game. printBoard();

//Prints the first row of turns taken
for(int row = 0; row < 3; row++)
{
if(game. pickLocation(0, row))
{
game. takeTurn(0, row);
}
}
System. out. println("\nAfter three turns:");
game. printBoard();

}
}

public class TicTacToe
{

private int turn;
private String[][] board = new String[3][3];

public TicTacToe()
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; 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()
{

}

//This method returns true if space row, col is a valid space
public boolean pickLocation(int row, int col)
{
return true;
}

//This method places an X or O at location row, col based on the int turn
public void takeTurn(int row, int col)
{

}

//This method returns a boolean that returns true if a row has three X or O's in a row
public boolean checkRow()
{
return true;
}

//This method returns a boolean that returns true if a col has three X or O's
public boolean checkCol()
{
return true;
}

//This method returns a boolean that returns true if either diagonal has three X or O's
public boolean checkDiag()
{
return true;
}

//This method returns a boolean that checks if someone has won the game
public boolean checkWin()
{
return true;
}

}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 19:00
If your accelerator suddenly gets stuck what should you do
Answers: 2
question
Computers and Technology, 23.06.2019 01:40
You have a linux system that has a 1000gb hard disk drive, which has a 90gb partition containing an ext4 filesystem mounted to the / directory and a 4gb swap partition. currently, this linux system is only used by a few users for storing small files; however, the department manager wants to upgrade this system and use it to run a database application that will be used by 100 users. the database application and the associated data will take up over 200gb of hard disk space. in addition, these 100 users will store their personal files on the hard disk of the system. each user must have a maximum of 5gb of storage space. the department manager has made it very clear that this system must not exhibit any downtime as a result of hard disk errors. how much hard disk space will you require, and what partitions would you need to ensure that the system will perform as needed? where would these partitions be mounted? what quotas would you implement? what commands would you need to run and what entries to /etc/fstab would you need to create? justify your answers.
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Which demographic challenge is europe currently experiencing? a. an aging and decreasing population b. a baby boomc. an unequal distribution between males and females d. a large group of teenagers moving through the school system(i chose a but i'm unsure)
Answers: 1
question
Computers and Technology, 23.06.2019 23:40
4. what is the reason for including the following code snippet in the header file animal.h? #ifndef animal_h #define animal_h class animal { public: animal(); animal(double new_area_hunt); void birth(); void hunt(double new_area_hunt); void death(); double get_area_hunt() const; private: double area_hunt; }; #endif
Answers: 3
You know the right answer?
For this exercise, you will complete the TicTacToe Board that we started in the 2D Arrays Lesson. W...
Questions
question
Mathematics, 08.02.2021 21:40
question
Mathematics, 08.02.2021 21:40
Questions on the website: 13722367