Question: Using Java ie introduction to object oriented programming language Please use the class file below to complete the work. 1)Create a class that creates an

Using Java ie introduction to object oriented programming language

Please use the class file below to complete the work. 1)Create a class that creates an instance of MyGliderHW. 2)Impliment the countNeighbors method in the MyGliderHW class.

/* * a class for working with Gliders * Spring 2017 update * */ public class MyGliderHW { private char[][] gameBoard; private char[][] glider = {{' ','*',' '}, {' ','*','*'}, {'*',' ','*'} }; /* constructor */ public MyGliderHW() { //assume gameboard is 10 x 10 gameBoard = new char[10][10]; } /* * prints a glider */ private void printGlider() { for(int i = 0; i < glider.length; i++) { for(int j = 0; j < glider[i].length; j++) { System.out.print(glider[i][j]); } System.out.println(); } } /* * put a glider into the gameboard starting at row r * column c * Note: There is no error checking for edges!!! */ public void putGlider(int r, int c) { System.out.println("Putting glider at: "+r+","+c); int gliderRow = 0; int gliderCol; for(int i= r-1; i < ((r-1)+glider.length); i++) { gliderCol = 0; for(int j =c-1; j < ((c-1)+glider.length); j++) { gameBoard[i][j] = glider[gliderRow][gliderCol++]; } //advance to next row in glider matrix gliderRow++; } //print the board printBoard(); //TODO : Count the neighbors } /* * print the game board */ public void printBoard() { System.out.println("Printing the game board"); for(int i =0; i < gameBoard.length; i++) { for(int j = 0; j< gameBoard[i].length; j++) { System.out.print(gameBoard[i][j]); } System.out.println(); } } /* * count the neighbors * no error checking */ private int countNeighbors(int r, int c) { int count = 0; //TODO: implement this method return count; } } ///~ 

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!