Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.Scanner; public class PoD { public static String[][] connectBoard( int width, int height, int[] moves ) { String[][] board = new String[width][height]; int[] columnCount

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

import java.util.Scanner;

public class PoD {

public static String[][] connectBoard( int width, int height, int[] moves ) {

String[][] board = new String[width][height]; int[] columnCount = new int[width]; // PLEASE START YOUR WORK HERE //PLEASE END YOUR WORK HERE return board; }

public static void main( String [] args ) { Scanner in = new Scanner( System.in ); int width = in.nextInt(); int height = in.nextInt(); int numberOfMoves = in.nextInt(); int[] moves = new int[numberOfMoves]; for (int i=0; i= 0; y--) { for (int x=0; x

} } }

Instructions You are going to write a connectBoard() method that takes a width, a height and a list of moves and builds the corresponding Connect-4 board. Not familiar with the game? Read this! Write the body of the program. Details of connectBoard() method You will be creating a new method called connectBoard). The main method input method call and output have been taken care of for you. Details of your new method are below: Input: Parameters The connectBoard() method will take the following parameters: an integer (Width): the width of the board an integer (helght]: height of the board an integer array (moves): containing integers in the range of Ito width (inclusive) Processing Create a width x height Connect-4 board represented by a 2D string array. Each of the integers in moves is gives the column where a piece is dropped: 1 is the first column (from left to right), width is the last. Output: Return value The connectBoard) will output a 2D string array where a cell is null if no piece is present. Otherse, the cell will contain ***. Sample Input/output: Sample connectBoard() Input Sample connectBoard() output Resulting Board 1 3 2 3 1 1 4 1 3 4 7. import java.util.Scanner; 9. /* Problem: Connect 4 Task: write a connectBoard method that takes a width, a height, and list of moves and builds the corresponding Connect-4 board. Params: int width : width of the board int height : height of the board int [] moves : integers in the range 1 ... width (inclusive) Processing: Create a width x height Connect-4 board represented by a 2D String array. h of the integers in moves is a column where to "drop" the piece: 1 is the first column width is the last. Outout: String [][] : a 2D array where a cell is null if no piece is present, otherwise the cell contains the string *** Example: If the arguments to the function are 2 3 4 3 4 4 4 the resulting board will look like 38. public class PoD { * Takes a width, a height, and list of moves and builds the corresponding Connect-4 board. * @param width Integer width of the board * @param height Integer height of the board * @param moves Array of integers, each in the range 1 ... width (inclusive) * @return A 2D String array where a cell is null if no piece public static String[][] connectBoard( int width, int height, int[] moves ) { //Declare 2D string array to hold depiction of a width x height Connect-4 board String[][] board = new String[width][height]; //Integer array to hold count of pieces in each column int[] columnCount = new int[width]; // PLEASE START YOUR WORK HERE //PLEASE END YOUR WORK HERE return board; public static void main(String [] args) { Scanner in = new Scanner(System.in); int width = in.nextInt(); int height = in.nextInt(); int numberOfMoves = in.nextInt(); //Declare and initialize the moves array int[] moves = new int[numberOfMoves); 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

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

Semantics Of A Networked World Semantics For Grid Databases First International Ifip Conference Icsnw 2004 Paris France June 2004 Revised Selected Papers Lncs 3226

Authors: Mokrane Bouzeghoub ,Carole Goble ,Vipul Kashyap ,Stefano Spaccapietra

2004 Edition

3540236090, 978-3540236092

More Books

Students also viewed these Databases questions

Question

Distinguish between aptitude and achievement tests.

Answered: 1 week ago

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago