Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

change all the items in the two dimensional Array to a blank character, in other words . Afterwards, it will have a print statement to

change all the items in the two dimensional Array to a blank character, in other words . Afterwards, it will have a print statement to let the user know that the board was reset.

public static void drawBoard(char[][] board) { for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (i % 2 == 1) { System.out.print("-"); } else { if (j % 2 == 1) { System.out.print("|"); } else { System.out.print(board[i / 2][j / 2]); } } } System.out.println(); } } public static void resetBoard(char[][]board){ } public static boolean checkWinner(char[][]board){ } public static void checkFullBoard(char[][]board){ }

public static void main(String[] args) { // TODO code application logic here Scanner scan = new Scanner(System.in); char [][] board = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}}; drawBoard(board); int row, col; String winner = "Nobody"; while(winner.equals("Nobody")){ System.out.print("Player X choose your spot: "); row = scan.nextInt(); col = scan.nextInt(); while(board[row][col]!= ' '){ System.out.print("Spot taken, please choose again:"); row = scan.nextInt(); col = scan.nextInt(); } board[row][col] = 'X'; drawBoard(board); checkFullBoard(board); if(checkWinner(board)){ winner = "X"; break; } System.out.print("Player O choose your spot: "); row = scan.nextInt(); col = scan.nextInt(); while(board[row][col]!= ' '){ System.out.print("Spot taken, please choose again:"); row = scan.nextInt(); col = scan.nextInt(); } board[row][col] = 'O'; drawBoard(board); checkFullBoard(board); if(checkWinner(board)){ winner = "O"; break; } } System.out.print(winner + " has won the game!"); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago