Question: 5) Write the Java method with this header public static void moveRobot(int [][] cells, int [] pos) cells[][] is a 2-dimensional array with any number

5) Write the Java method with this header

public static void moveRobot(int [][] cells, int [] pos) cells[][] is a 2-dimensional array with any number of rows and columns. It is a rectangular array (i.e., all rows have the same number of columns). Each element or square of the cells[][] array contains either a 1 or 0, no other integers. pos[] is an array of two integers. There is a robot on the cells array, on the square at cells[i][j]. pos[0] contains i, pos[1] contains j. Directions are defined in the usual way for a 2-dimensional array (i.e., same as your Ant and Robot projects). moveRobot() moves the robot one step, according to these rules (applied in order): if the square to the left of the robot and the square to the right of the robot both contain 0, then the robot moves down one square, otherwise if the square above the robot and the square below the robot both contain 0, then the robot moves right one square. If at any time the robot tries to move outside the cells[] array, place the robot at i=0, j=0. Update the pos[] array to keep track of the movement. You dont have to display anything.

5) Write the Java method with this header public static void update(int [][] grid) grid[][] is a 2-dimensional array with any number of rows and columns. It is a rectangular array (i.e., all rows have the same number of columns). Each cell of the array contains either a 1 or 0, no other integers. update() checks all cells in the array for this 3 x 3 pattern: 1 1 0 0 1 0 0 0 1 When the above pattern is found the middle cell is changed to 0, to get this new pattern: 1 1 0 0 0 0 0 0 1 Write the update() method. 25 points

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!