Computers and Technology
Computers and Technology, 06.04.2021 01:50, Kurlyash

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;
}

}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 11:00, shawn20034
This chapter lists many ways in which becoming computer literate is beneficial. think about what your life will be like once you’re started in your career. what areas of computing will be most important for you to understand? how would an understanding of computer hardware and software you in working from home, working with groups in other countries and contributing your talents.
Answers: 1
image
Computers and Technology, 23.06.2019 22:20, Izzyfizzy
Read “suburban homes construction project” at the end of chapters 8 and 9 (in the textbook) and then develop a wbs (work breakdown structure) in microsoft excel or in microsoft word (using tables)
Answers: 1
image
Computers and Technology, 25.06.2019 01:30, parislover2000
What controls can be found on the file tab of microsoft word
Answers: 1
image
Computers and Technology, 25.06.2019 10:00, jordan84546
Which of the following methods could be considered a “best practice” in terms of informing respondents how their answers to an on-line survey about personal information will be protected? the investigator uses the informed consent process to explain how respondent data will be transmitted from the website to his encrypted database without ever recording respondents’ ip addresses, but explains that on the internet confidentiality cannot be absolutely guaranteed. respondents are informed that investigators will try to keep their participation confidential; however, confidentiality cannot be assured. the investigator uses the informed consent process to explain her institution’s method for guaranteeing absolute confidentiality of research data. respondents are informed that a research assistant will transfer all the research data to a password-protected computer that is not connected to the internet, via a usb flashdrive. the computer is located in a research team member’s office.
Answers: 2
Do you know the correct answer?
For this exercise, you will complete the TicTacToe Board that we started in the 2D Arrays Lesson. W...

Questions in other subjects: