Question: Can you change my code so that it uses the becker robot package instead and uses the concept of inheritance. This is my code: //Author:

Can you change my code so that it uses the becker robot package instead and uses the concept of inheritance.

This is my code:

//Author: Raphael Pinto //ICS4U //ROUGH DRAFT without robots

import java.util.Scanner;

public class Connect4 {

public static void main(String[] args) { Scanner in = new Scanner(System.in); //Creating the size of the board char[][] grid = new char[6][7]; //Here we are itializing the array for (int row = 0; row < grid.length; row++){ for (int col = 0; col < grid[0].length; col++){ grid[row][col] = ' '; } } //Starting move int turn = 1; char player = 'R'; boolean winner = false; //The player can take a turn while (winner == false && turn <= 42) { boolean validPlay; int play; do { display(grid); System.out.print("Player " + player + ", choose a column: "); play = in.nextInt(); //We are checking if the play is valid validPlay = validate(play,grid); } while (validPlay == false); //Here the checker drops for (int row = grid.length-1; row >= 0; row--) { if(grid[row][play] == ' ') { grid[row][play] = player; break; } } //Checking to see if there is a winner winner = isWinner(player,grid); //Switch players if (player == 'R') { player = 'B'; } else { player = 'R'; } turn++; } display(grid); if (winner) { if (player=='R') { System.out.println("Black won"); } else { System.out.println("Red won"); } } else { System.out.println("Tie game"); } } //Public Static Main Bracket KEEP //Creating board **without use of robots** public static void display(char[][] grid){ System.out.println(" 0 1 2 3 4 5 6"); System.out.println("---------------"); for (int row = 0; row < grid.length; row++) { System.out.print("|"); for (int col = 0; col < grid[0].length; col++) { System.out.print(grid[row][col]); System.out.print("|"); } System.out.println(); System.out.println("---------------"); } System.out.println(" 0 1 2 3 4 5 6"); System.out.println(); } //Public Static Main Bracket KEEP //**fixing holes in the code**// public static boolean validate(int column, char[][] grid){ //Checking if the column is valid if (column < 0 || column > grid[0].length) { return false; } //Checking if the column is full if (grid[0][column] != ' ') { return false; } return true; } //Public Static Main Bracket KEEP public static boolean isWinner(char player, char[][] grid) { //checking for 4 counters across for(int row = 0; row

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!