Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need someone to fix my code, I need to write a TicTacToe, I wrote it and I didn't get the same output as the

I need someone to fix my code, I need to write a TicTacToe, I wrote it and I didn't get the same output as the requirement. Also, I only know how to wrote it in one Java, I don't how to separate to write it on three different class which is TicTacToe, Board and TicTacToe Tester. Can someone help me out? image text in transcribed

image text in transcribed

image text in transcribedHere is the code that I wrote. I really need help this.

import java.util.Scanner; public class TicTacToe { public static int[][] Chess=new int[3][3]; public static int player=1; public static int count=0; public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Welcome to Tic Tac Toe !"); while(true) { while(true) { System.out.print("Enter the X and Y coordinates of your next move, e.g 0 2 or 1 1, or 'quit' to exit."); if(player == 1) System.out.print(" X's turn! "); else System.out.print(" O's turn! "); int row = input.nextInt(); System.out.print("Enter the X and Y coordinates of your next move, e.g 0 2 or 1 1, or 'quit' to exit."); if(player == 1) System.out.print(" X's turn! "); else System.out.print(" O's turn! "); int column = input.nextInt(); if (Judgingrange(row, column, player) == true) { break; } } ShowCheckerboard(); if (JudgingWin(player) == true) { if (player==1) System.out.println("X player win"); else System.out.println("O player win"); System.out.print("Would you like to continue? (Y or N):"); String choose = input.next(); if (choose.equals("Y")) { for (int i=0; i 2 || y 2 ) { System.out.println("Input out, please input again."); return false; } if (Chess[x][y] == 0) { Chess[x][y] = num; count++; return true; } else { System.out.println("There's already a piece, Input out, please input again."); return false; } } public static boolean JudgingWin(int num) { for (int i = 0; i Welcome to Tic Tc Toe! X's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. ---|---|--- O's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. 1 1 ---|---|--- ---|---|--- X's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. 1 2 ---|---|--- ---|---|--- O's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. 2 2 ---|---|--- ---|---|--- X's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. I ---|---|--- ---|---|--- O's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. XI0IX ---|---|--- ---|---|--- X's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. 2 1 XI ---|---|--- |0| X ---|---|--- O's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. XI0IX ---|---|--- 0 10| X ---|---|--- X's turn! Enter the X and Y coordinates of your next move, e.g. 0 2 or 1 1, or 'quit' to exit. XI0I X ---|---|--- ---|---|--- XIXI0 It's a tie! Process finished with exit code 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions