Question: please someone help with the question Java (b) Write a command line game with the following functionality: The application should prompt the user for an

please someone help with the question

Java

(b) Write a command line game with the following functionality: The application should prompt the user for an odd integer and create a magic square of that size. The magic square should then be shuffled by repeatedly (for n2 times) choosing a random element and swapping it with a random neighbour (not including diagonals). The shuffled square should be displayed to the user, who must attempt to reconstruct a magic square. The user makes moves by giving input of the form:

i j direction

where i and j specify the row and column of an element to be swapped, and direction (either U, D ,L ,R representing up, down, left and right) specifies which direction it should be swapped with. For example, the move 2 1 D applied to the square above would give:

6 1 8 2 5 3 7 9 4

On completion, the game should report the number of moves made. (18 Marks) [Functionality: 5, Design: 10, Ease of use: 2, Presentation: 1

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

HINT: MULTIDIMENSIONAL ARRAYS The code below gives an example of using a 2-dimensional array to store values:

public class MultiArrayTest { public static void main ( String [] args ) { int a [][] = {{1 ,2 ,3} , {4 ,5 ,6}}; System . out . println ( " length of a is " + a . length ) ; for (int i = 0; i < a . length ; i ++) { for (int j = 0; j < a [ i ]. length ; j ++) { System . out . print ( a [ i ][ j ] + " " ) ; } System . out . println () ; } } }

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!