Question: Using two dimensional arrays, create a program to play game of Tic Tac Toe. Your program enables you to play against the computer. Use the

Using two dimensional arrays, create a program to play game of Tic Tac Toe. Your program enables you to play against the computer.

Use the following skeleton and complete the given methods.

import java.util.*; public class TicTacToe { static Scanner in = new Scanner(System.in); public static void main(String[] args) { Scanner in = new Scanner(System.in); char[][] board = new char[3][3]; for(int i=0;i<3;i++) for(int j=0;j<3;++j) board[i][j]=' '; while (true) { computerPlay(board); displayBoard(board); if(checkWin(board,'X')) { System.out.println("Computer Wins"); System.exit(0); } if(checkTie(board)) { System.out.println("Tie game"); System.exit(0); } playerPlays(board); displayBoard(board); if(checkWin(board,'O')) { System.out.println("Player Wins"); System.exit(0); } if(checkTie(board)) { System.out.println("Tie game"); System.exit(0); } } } public static void playerPlays(char[][] board) { // Prompt the user for row & column index. Continue asking // until an empty cell is selected. set the cell to 'O' }

public static boolean checkWin(char[][] board,char ch) { // Check by row, column, and diagonals } public static boolean checkTie(char[][] board) { // check for tie. If there no empty cells, then it is a tie }

public static void displayBoard(char[][] board) { // Display the board } public static void computerPlay(char[][]board) { // Continue generating random values for row and col until an // empty cell selected. Set the cell to 'X' } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!