The objectives of this assignment are:
This assignment is all about creating and using a Java class. You start by creating a TicTacToe class which represents a TicTacToe board. You then have to develop the code that uses the TicTacToe class to actually play a game of TicTacToe. You should use the sample output given on this page to test your program.
create TicTacToe object
initialize variables
while the user want to play another game
reset the TicTacToe board
display game instructions
display the TicTacToe board
while the game is still active
get a valid move from the user
make the move
display the TicTacToe board
display the game status (who won or if it was a draw)Note: Program must compile without errors.
This is the game of Tic Tac Toe. X moves first. Each player chooses their move by selecting the cell they want to place their mark in. The cells are numbered as follows: 1 2 3 4 5 6 7 8 9 | | ----------- | | ----------- | | Enter move for player X: bob Error: Invalid integer Enter move for player X: 10 Error: Integer above maximum value (9) Enter move for player X: 0 Error: Integer below minimum value (1) Enter move for player X: 5 | | ----------- | X | ----------- | | Enter move for player O: 1 O | | ----------- | X | ----------- | | Enter move for player X: 2 O | X | ----------- | X | ----------- | | Enter move for player O: 8 O | X | ----------- | X | ----------- | O | Enter move for player X: 6 O | X | ----------- | X | X ----------- | O | Enter move for player O: 2 Enter move for player O: 1 Enter move for player O: 4 O | X | ----------- O | X | X ----------- | O | Enter move for player X: 3 O | X | X ----------- O | X | X ----------- | O | Enter move for player O: 7 O | X | X ----------- O | X | X ----------- O | O | Player O has won. Play again (Y/N)? bob Invalid choice Play again (Y/N)? r Invalid choice Play again (Y/N)? y This is the game of Tic Tac Toe. X moves first. Each player chooses their move by selecting the cell they want to place their mark in. The cells are numbered as follows: 1 2 3 4 5 6 7 8 9 | | ----------- | | ----------- | | Enter move for player X: 1 X | | ----------- | | ----------- | | Enter move for player O: 5 X | | ----------- | O | ----------- | | Enter move for player X: 9 X | | ----------- | O | ----------- | | X Enter move for player O: 6 X | | ----------- | O | O ----------- | | X Enter move for player X: 4 X | | ----------- X | O | O ----------- | | X Enter move for player O: 7 X | | ----------- X | O | O ----------- O | | X Enter move for player X: 3 X | | X ----------- X | O | O ----------- O | | X Enter move for player O: 2 X | O | X ----------- X | O | O ----------- O | | X Enter move for player X: 8 X | O | X ----------- X | O | O ----------- O | X | X The game is a draw. Play again (Y/N)? sam Invalid choice Play again (Y/N)? 5 Invalid choice Play again (Y/N)? n