Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need the answer for the question i do not want the code in java program Lab Re

ID: 3739682 • Letter: I

Question

i need the answer for the question i do not want the code in java program

Lab Report Questions:

Why is it a good idea to sepearte the backend code from the frontend (user interface)?

Is it possible to create ragged arrays of objects in Java?

Objective:

Create a simple game of mine sweeper with the following classes and a driver

Download the driver

Put the driver in your project

DO NOT ALTER THE DRIVER!

Write a class file called MineSpace

Attributes of this class

Selected – determines whether or not this space has been clicked on

IsAMine – this is whether or not it is a mine

SurroundingMines – The number of mines surrounding that space

Create a default constructor with the following

Selected is set to false

IsAMine is randomly set to either true or false

Create Accessors and Mutators for each instance variable

MAKE SURE TO CHECK FOR VALID VALUES

Write another class SimpleMineSweeperBackEnd

Attributes of this class are

Spaces – a 2D array of type mine space

SPACE_AMT – a constant value set to 5 as this is a 5x5 minefield

numNotMinesLeft – the number of mines left on the board

gameOver – whether or not the game is over

win – whether or not the player wins

Create a default constructor

Declare the 2D array

Call reset spaces

Create the following Methods

resetSpaces – this method returns nothing and takes no parameters constructs each individual space and counts the number of not mines. It also sets each mine surroundingMines value by looking at each of its neighbors (HINT: looking setting the number of mines value maybe best done in a private method). Also it sets both gameOver and win to false.

getNumNotMinesLeft – returns how many spaces that aren’t mines remain

getGameOver – returns whether or not the game is over

getWin – returns whether or not the player has won

printMines – prints each mine space in the 2D array. It should print whether or not it is a mine and the number of surrounding mines. This is really good for debugging.

selectSpace – this method which returns an instance of Space takes in two integers corresponding to the button that was selected. Much like other projects the x increase left to right and the y increases from top to bottom. This method should check if it is already select. If it hasn’t been then set selected to true. Next check if that space is a mine. If it is then set gameOver to true and win to false. If not then subtract the number of not mines left. Next check if the number of not mines is 0 then game over should be set to true and win should be set to true.

Example:

Lab Report Questions:

Why is it a good idea to sepearte the backend code from the frontend (user interface)?

Is it possible to create ragged arrays of objects in Java?

Mines: 9 LOSER! Game Over

Explanation / Answer

1. It is definitely a good idea to separate the backend code from the frontend. First, the frontend does not need to know the work which is being held at the backend. It only have to work for the frontend and the user should see the frontend only. It can be explained with an example. Like when we use an ATM, as a user, we do not want to know how the money is counted and how the receipt is printed or any of the stuff. So we as a frontend do not want to know the backend processes.

Also, it can be the need of the backend to protect the code so that it does not go into wrong hands and to maintain the security of the organisation. Backend code might be very secret and for some security purposes, it should always be hidden or separated from the frontend.

These are the major and strong enough points to separate the backend and frontend code.

2. It is very much possible to create a ragged array in java. Just like a normal ragged array of primitive data types, ragged array of objects can also be created. Following code explains it.

public class Main

{

       public static void main(String[] args)

       {

             Class object[][] = new Class[2][];

             object[0] = new Class[2];

             object[1] = new Class[4];

             object[0][0] = new Class();

             object[0][0].variable = 10;

             object[0][1] = new Class();

             object[0][1].variable = 20;

             object[1][0] = new Class();

             object[1][0].variable = 100;

             object[1][1] = new Class();

             object[1][1].variable = 200;

             object[1][2] = new Class();

             object[1][2].variable = 300;

             object[1][3] = new Class();

             object[1][3].variable = 400;

             for(int i = 0; i < 2; i++)

             {

                    System.out.println();

                    for(int j = 0; j < object[i].length; j++)

                           System.out.print(object[i][j].variable + " ");

             }

       }

}

class Class

{

       int variable;

}

This program displays the following output.

10     20    

100    200    300    400