Question: PLEASE DO THE ONES HIGHIGHTED IN BOLD. the answer should be where it says throw new RuntimeException(Not implemented);. Thank you. Directions are there above the

PLEASE DO THE ONES HIGHIGHTED IN BOLD. the answer should be where it says "throw new RuntimeException("Not implemented");". Thank you. Directions are there above the function, it is not supposed to throw not implemented. Instead there should be a code there.

package hw3;

public class Board {

private char[][] board;

private char player1;

private char player2;

private char winner;

private int move_count;

// Add whatever private fields you need here.

// Remember, only variables of type int, char, boolean, and 1D and 2D arrays

// of these types are allowed.

//

// As always, you may also add private helper methods to the class. That will

// likely be very useful on this assignment.

/**

* Constructs a new empty connect 4 game board with player X being the first player

* and player 'O' being the second player.

*/

public Board() {

this.board = new char[6][7];

char empty = '0';

for(int i = 0; i < board.length; i++) {

for(int j = 0; j < board[i].length; j++) {

board[i][j] = empty;

}

}

this.player1 = 'X';

this.player2 = 'O';

}

/**

* Gets the current player (either 'X' or 'O')

*

* @return the current player

*/

public char currentPlayer() {

int move_cnt1 = 0;

int move_cnt2 = 0;

for(int i = 0; i < 6; i++) {

for(int j = 0; j < 7; j++){

if (board[i][j] == this.player1) {

move_cnt1++;

}

else if(board[i][j] == this.player2) {

move_cnt2++;

}

}

}

if(move_cnt1 == move_cnt2) {

this.move_count = move_cnt1 + move_cnt2;

return this.player1;

}

else {

this.move_count = move_cnt1 + move_cnt2;

return this.player2;

}

}

/**

* The current player makes a move in a given column if it is a valid move.

* Throws an exception if the game is already over.

*

* @param column the column in which to make a move. For the move to be valid,

* the column value must an {@code int} between 1 and 7 inclusive, and

* there must have been fewer than 6 moves already made in the given column.

* @return {@code true} if the move is valid and false if it is not valid.

* @throws RuntimeException if the game is already over.

*/

public boolean play(int column) {

throw new RuntimeException("Not implemented");

}

/**

* Determine the status of the game.

*

* @return {@code 'X'} or {@code 'O'} if either player has won, {@code 'D'} if

* the game is a draw, and {@code 'U'} if the game is still undecided.

*/

public char gameStatus() {

throw new RuntimeException("Not implemented");

}

/**

* Construct a string that depicts the sate of the game.

* (See the writeup for what that string should look like.)

*

* @return a string depicting the game board

*/

public String toString() {

//return "toString() method not implemented.";

String aString = "";

String divider1 = "-------------------";

String header = "1 2 3 4 5 6 7 ";

String divider = "-------------------";

aString += divider1 + " " + header + " " + divider + " ";

for(int i = 0; i < board.length; i++)

{

for(int j = 0; j< board[i].length; j++)

{

aString += (board[i][j] + " ");

//if(j < board[i].length - 1)

System.out.print(" ");

//aString +=board[i][j] + " " + " ";

}

aString += " ";

//System.out.println();

}

return aString;

//constructs a string that looks like the board

//return aString;

}

}

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 Programming Questions!