Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

[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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Evaluate employees readiness for training. page 275

Answered: 1 week ago