Question: ========================================== Using Java to create the Connect 4 board game; Must follow the structure and instructions to place the answer instead of throw new RuntimeExpection(Not

========================================== Using Java to create the Connect 4 board game; Must followthe structure and instructions to place the answer instead of "throw newRuntimeExpection("Not implemented"); The non-colored sentences are instructions; Thanks * x 1 package==========================================

Using Java to create the Connect 4 board game;

Must follow the structure and instructions to place the answer instead of "throw new RuntimeExpection("Not implemented");

The non-colored sentences are instructions;

Thanks

* x 1 package hw3; 2 30 import edu.princeton.cs.algs4.StdIn;. 5 6 public class Board { 7 // Add your own PRIVATE fields here. 8 // They must have type char, int, boolean, String, or they can be 10 or 2D arrays of these types. 9 106 /*** 11 * Constructs a new empty connect 4 game board with player X being the first player 12 * and player 'O' being the second player. 13 */ 140 public Board() { 15 throw new RuntimeException ("Not implemented"); 16 } 17 186 /** 19 * Gets the current player (either 'X' or '0') 20 21 * @return the current player 22 */ 230 public char currentPlayer() { 24 throw new RuntimeException ("Not implemented"); 25 } 26 27@ 28 * The current player tries to make a move in a given column. If the move 29 * is valid, the board is updated and {@code true} is returned. If the move 30 * is invalid (not a valid column number of the column is already full) 31 * the board remains unchanged and {@code false} is returned. If the game is 32 * already over, a RuntimeException is thrown instead. 33 34 * @param column the column in which to make a move. For the move to be valid, 35 * the column value must an {@code int} between 1 and 7 inclusive, and 36 * there must have been fewer than 6 moves already made in the given column. 37 * @return {@code true} if the move is valid and false if it is not valid. 38 * @throws RuntimeException if the game is already over. 39 */ 400 public boolean play(int column) { 41 throw new RuntimeException("Not implemented"); 42 } 43 44 45 * B88 ** /** * Determines if the game is already over. * @return {ac.code true} if the game is over and {@code false} if it is not over. */ public boolean gameOver() { throw new RuntimeException("Not implemented"); } * /*** * Determine the winner (assuming the game is over). * @return {@code 'X'} or {@code '0'} if either player has won and {@code ''} * if the game is not over or if the game is a draw. */ public char winner() { throw new RuntimeException("Not implemented"); } 466 47 48 49 50 510 52 53 54 550 56 57 58 59 60 610 62 63 64 650 66 67 68 69 70 71 A 720 73 74 75 760 77 78 79 800 81 82 83 84 85 86 87 88 89 * * Construct a string describing the state of the game. You are not reguried to implement * this method, however, implementing this method will make debugging much easier so * you are encrouaged to implement this to return a string that looks like the game board. * @return a string representation of the game */ public String toString() { return "toString() method not implemented."; } * This main can be used to play a game of Connect 4. In order to display the game board * you must have defined the toString method. */ public static void main(String[] args) { Board b = new Board(); while (!b.gameOver()) { boolean lega lMove = false; while (!lega lMove) { Stdout.println(" "); Stdout.println(b); Stdout.println("Current player: " + b.currentPlayer()); Stdout.println("Enter column number for next move: "); int col = stdin.readInt(); 89 90 91 92 93 94 95 96 97 98 99 100 101 } 102 int col = StdIn.readInt(); legalMove = b.play(col); } } Stdout.println(" "); Stdout.println(b); Stdout.println("GAME OVER"); if (b.winner() = '') Stdout.println("It's a draw"); else Stdout.println(b.winner() + WINS!!!"); }

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!