Question: Java programming [40 marks] Create a 10x10 matrix as a 2D array. See a sample array below. 0 4 9 0 R1[0, 0] [0, 1]

Java programming

Java programming [40 marks] Create a 10x10 matrix as a 2D array.See a sample array below. 0 4 9 0 R1[0, 0] [0,

[40 marks] Create a 10x10 matrix as a 2D array. See a sample array below. 0 4 9 0 R1[0, 0] [0, 1] [0, 2] [0, 3] [0, 4][o,9] 2 [2,0] [2, 1] [2, 2] [2, 3] 2,4][2,9] Assume that a robot is placed in position [0, 0]. Now randomly generate a move. The move could take the robot to one of the eight possible adjacent slots - (up, down, left, right, left-up- corner, left-down-corner, right-up-corner, and right-down-corner]- these slots are represented by (1, 2, 3, 4,5,6,7, 8). However, at [0, 0], the robot only has three possible slots to move to- right, down, right-down-corner Create another robot called R2 and place it on [9, 9] Now randomly generate an integer in the range of [1 to 8]. This first random integer corresponds to a possible move for Robot R1. If the move is valid, then move R1 to its new slot. A move is invalid if it takes the robot out of bounds of the [10x10] matrix. If the move is invalid, then keep generating random integers until a valid move is found. Repeat this procedure for the second Robot R2 If both R1 and R2 are in the same slot, then stop, print the final slot, print the sequence of random numbers that led R1 to this slot, and the print the sequence of random numbers that led R2 to the same slot. Implement this program with a Robot class and a MovingRobot subclass. Robot a Attributes + int X + int y + public static final int DOWN + public static final int LEFT +public static final int LEFT_DOWN CORNER +public static final int LEFT_UP CORNER + public static final int RIGHT +public static final int RIGHT DOWN CORNER + public static final int RIGHT UP CORNER + public static final int UP Operations + public int getXO + public int getYO +public Robot(int x, int y) +public void setX(int x) +public void setY(int y) MovingRobot a Attributes +ArrayList moves + int nextMove Operations public boolean validateNextMove() + public int generateNextMove() +public MovingRobot (int x, int y) + public static boolean sameSlot(Robot r1, Robot r2) + public String printMoves() + public void move()

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!