Question: Making connect-four program with java code with 3 methods. just incase, the picture below is connect-four. 1. public static void printPattern(String[][] brd) Takes the board

Making connect-four program with java code with 3 methods.

just incase, the picture below is connect-four.

Making connect-four program with java code with 3 methods. just incase, the

1. public static void printPattern(String[][] brd)

Takes the board as an argument and prints the pattern of the updated board every time the player drops their respective disks.

2. public static void dropDisk(String[][] brd, int positin, int player)

This method takes three arguments, the board , the position where the player wants to drop his/her disk and the player number( 1 or 2).

It then puts the disk in the right position for the right player.

3. public static String checkWinner(String[][] f)

This method takes the board every time it is updated to check if there is a winner. If there is a winner then it returns the winners color to the caller

So I wrote basic structure. (Code is below from here)

package connectfour;

import java.util.Scanner;

public class ConnectFour { public static void main (String[] args) { // DON'T MODIFY THE MAIN METHOD UNLESS FOR DEBUGGING //MAKE SURE YOU GET RID OF YOUR MODIFICATIONS HERE BEFORE SUBMISSION

String[][] board = createEmptyBoard();

Scanner input = new Scanner(System.in);

boolean bl = true;

printPattern(board);

while(bl) { int player1 = 1 , player2 = 2 , userInput; System.out.println("Please drop a RED disk at the column between 0 and 6:"); userInput = input.nextInt(); dropDisk(board, userInput , player1); printPattern(board); System.out.println("Please drop a YELLOW disk at the column between 0 and 6:"); userInput = input.nextInt(); dropDisk(board, userInput , player2); printPattern(board);

String win = checkWinner(board); /* Write code to announce if there is winner and end the game */

} // end of while loop

} // end of main public static String[][] createEmptyBoard() { /* This method prints the first empty pattern for the game DON'T MODIFY THIS METHOD */ String[][] f = new String[7][15]; for (int i =0;i

if (j% 2 == 0) f[i][j] ="|"; else f[i][j] = " "; if (i==6) f[i][j]= "-"; } } return f; } // end of createEmptyBoard public static void printPattern(String[][] brd) { //Trying to Write the code here to print an updated pattern public static void dropDisk(String[][] brd, int positin, int player) { } // end of dropDisk public static String checkWinner(String[][] brd) { /*Write your code to check if there is a winner. If there is, then return the charaster of the winners color( withe R or Y) */ String str = " "; return str; } // end of checkWinner } // end of class

Anyone can tell me what should I add or fix?

I wrote with capital that methods I must use. the image below is the result when I run the code few times.

picture below is connect-four. 1. public static void printPattern(String[][] brd) Takes the

OODOOOO OODOOOO o0OOO

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!