Question: Hello, I need help with the problem and I need it written in java. Thanks! Goal: Make a n x m grid where an X

Hello, I need help with the problem and I need it written in java. Thanks!

Goal: Make a n x m grid where an X "moves" from cell to cell.

  • Write a program. Class name MovingX.
  • Create two global variables, rowsN and columnsM.
  • Write a constructor that will populate those two global variables.

Write two methods to do the same thing.

Method 1: Make a method forLoopGrid()

  • Write nested loops to print out "[ ]". With two local variables x, y. They start at x = 0 and y = 0;
  • During your loop if i = x and j = y, then print out a "[ x ]" instead.
  • Once the whole grid is printed. x++ if x < the length of the rows. Else set x to 0 and y++.
  • Loop this whole procedure n x m times. Ie 9 times if your array is 3 x 3.

Method 2: Create a method arrayGrid().

  • It will use String[][] xPostion to keep track of the current position. Position [0][0] of the array should hold the initial position of the X.
  • Loop through the above array and print out "[ ]" in every cell except the first one, which will have "[ x ]".
  • After the full grid is printed, update the position of x from the grid to the next spot over and replace the previous cell with null.
  • Now loop this whole process n * m times. ie. a 3x4 array would be 12 iterations of this (minus the 1 you just did)

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!