Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java Instructions You are going to write a method to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is

java image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Instructions You are going to write a method to be called validateBoard) that is going to validate whether or not a Tic-Tac-Toe board is possible. Tic-Tac Toe is played on a 3 by 3 board and players take turns placing other an x or ano on the board. We will assume that in Tic-Tac Toe, the player placing x will go first and that will go second. Learn more about the game here: https://en wikipedia.org/wiki/Tic-tac-toe As the player placing x pieces goes first and play alternates, a valid board is one in which there is either the same number of one more x game places on the board as there are o game pieces The board is represented by a 3 by 3 array that holds strings that represent the game place at each location. A space can hold any of the following: "x", representing an x game place in that position . "o", representing an o game plece in that position ".", representing an empty position on the board Write the body of the program Details The main method of the program has been completed for you. You are to create the method called validateBoard' which is called from the main method. The validateboard method should take a 2D array as input and return a boolean value. Details of this method are below. Input The validateBoard method should take as input - a 2-dimensional array that holds strings representing the 3 by 3 game board where strings "x","o" and "." denoting the game piece in each location, as described above] - a 2 dimensional array that holds strings (representing the 3 by 3 game board where strings"x","o" and denoting the game piece in each location, as described above] Processing The new method will decide whether the incoming 2D array is represents game pieces, of one more x than o A vald bond is defined to be a board in which there are either the same number of xas o Output If the board is determined to be vald the method will return a boolean value of true Sample input/output: Sample input Sample output ("x", "0", "."). ("x", ".","x"), ("x","o","0") {"*","0","."). ("x", ".","."). ("*"."0","0 ) true ("x","x","."). ("x",".","."). ("x","0","0"} false 6- import java.util."; 8 - public class PoD ? Validates that a 3x3 Tic-Tac-Toe game board is a valid board. * 1.e. a board that has at most one more x than o on it. eparam gameBoard String[3][3] that holds game board info @return True if valid board, false otherwise. public static boolean validateBoard(String(d gameboard) boolean validBoard; //PLEASE START YOUR WORK HERE //PLEASE END YOUR WORK HERE return (validBoard); . public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner(System.in); int gamePiece; PoD.java New Exit Full Screen String[ tictactoeBoard - new String[3][3]; for (int i 0; i

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_2

Step: 3

blur-text-image_3

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

Introduction To Constraint Databases

Authors: Peter Revesz

1st Edition

1441931554, 978-1441931559

More Books

Students also viewed these Databases questions