Java.   Starter code: import java.util.*; public class PoD { public static boolean validateBoard(String[][] 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; String[][] ticTacToeBoard = new String[3][3]; for (int i=0; i<3; i++) { for (int j=0; j<3; j++) { //Read in board ticTacToeBoard[i][j] = in.next(); //Output board if (j<2) { System.out.print(ticTacToeBoard[i][j] + " "); } else { System.out.println(ticTacToeBoard[i][j]); } } } if (validateBoard(ticTacToeBoard)) { System.out.println("Valid board"); } else { System.out.println("Invalid board"); } } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Java.

 

Starter code:

import java.util.*;

public class PoD {

public static boolean validateBoard(String[][] 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;


String[][] ticTacToeBoard = new String[3][3];

for (int i=0; i<3; i++)
{
for (int j=0; j<3; j++)
{
//Read in board

ticTacToeBoard[i][j] = in.next();

//Output board
if (j<2)
{
System.out.print(ticTacToeBoard[i][j] + " ");
}
else
{
System.out.println(ticTacToeBoard[i][j]);
}
}
}


if (validateBoard(ticTacToeBoard)) {
System.out.println("Valid board");
}
else {
System.out.println("Invalid board");
}
}
}

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 either an x or an o on the board. We will assume
that in Tic-Tac-Toe, the player placing x will go first and that o 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 or one more x game pieces 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 piece at each location. A space can hold any of the following:
• "x", representing an x game piece in that position
"o", representing an o game piece 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 valldateBoard 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)
Processing
The new method will decide whether the incoming 2D array is represents a valid board. A valid board is defined to be a board in which there are either the same number of x as o game pieces, or one more x than o.
Output
If the board is determined to be valid, the method will return a boolean value of true. Otherwise, it will return false.
Transcribed Image Text: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 either an x or an o on the board. We will assume that in Tic-Tac-Toe, the player placing x will go first and that o 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 or one more x game pieces 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 piece at each location. A space can hold any of the following: • "x", representing an x game piece in that position "o", representing an o game piece 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 valldateBoard 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) Processing The new method will decide whether the incoming 2D array is represents a valid board. A valid board is defined to be a board in which there are either the same number of x as o game pieces, or one more x than o. Output If the board is determined to be valid, the method will return a boolean value of true. Otherwise, it will return false.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education