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

Java program....I\'ve had 4 incorrect answers so far, if it\'s wrong I will thum

ID: 669749 • Letter: J

Question

Java program....I've had 4 incorrect answers so far, if it's wrong I will thumbs down it.

Please read the assignment carefully!!

The bomb needs to be visible on the board AT ALL TIMES.

If I get the same answer I've gotten two times before I will triple thumbs down it.

This is a simplified minesweeper game. The player moves from the starting position on the board to the finish without stepping on a bomb.

Your program must work like this...

Player starts in upper left

Player moves one space at a time

Player can only move right or down. Ignore any other input.

Player cannot move off the board

Player wins when he/she reaches lower right corner

Player loses if he/she steps on a bomb

Your program should prompt for the size of the board. Ensure that input is at least size 3. Place one bomb for a 3X3 board. Add an additional bomb for each row above 3.

Bombs must be placed randomly. Your instructor will check this thoroughly.

Insure that bombs are not placed at the start or the finish.

Game board should be printed out in a user friendly fashion at the start and after each move, except the last. Since you are doing this as a homework exercise rather than a real game, your board display should show where the bombs are. This will make it easier for your instructor to grade your program.

See the 4 pages of sample output included in this document.

You are free to design your program any way you wish, with one stipulation. The intent of this exercise is to give you experience with arrays in Java. The game board must implemented in your program as an array.

Submit a single .java file. Programs that do not compile with receive a grade of 0.

This is due tomorrow...and I'm lost. Please help!

Sample outputs...must look just like this when ran:

Command Prompt MineSweeper3 C:Userskcare yDesktopFall15COP2800lectureslecture4java Welcome!! Are you an expert or a newbie? Enter a board size: 3 (d)own or right? r (d)own or right? r (d)own or right? d B_P (d)own or right? d You win! XUsers kcare yDesktop Fal115 COP280g lectureslecture4>

Explanation / Answer

package Cryptography;
import java.util.*;

public class Minesweeper
{
     public static void main(String[] args)
     {
         int rows,columns, num_mines;
         int board[][];
         int bombs[][];
         int numMines;
         Scanner user_input = new Scanner(System.in);

         System.out.println("Enter number of rows on the board");
         rows = user_input.nextInt();
         System.out.println("number of rows "+rows);
         if(rows<3)
         {
             System.out.println("At least 3 rows and 3 columns on board");
             System.out.println("Enter number of rows");
             rows = user_input.nextInt();
         }
         System.out.println("Enter number of columns on the board");
         columns = user_input.nextInt();
         System.out.println("number of columns "+columns);
         if(columns<3)
         {
             System.out.println("At least 3 rows and 3 columns on board");
             System.out.println("Enter number of columns");
             columns = user_input.nextInt();
         }
         board=new int[rows][columns];
         placeMines(board,1);
         if (rows==3)
        numMines=1;
        else
        numMines=numMines+rows;
   
    int minesPlaced = 0;
while (minesPlaced < numMines) {
     // Pick a random cell in which to place a mine.
     // NOTE: Cells are numbered 0 to length-1.
     // Be sure to avoid the border cells.
     int row = randomInt(1,board.length-2);
     int col = randomInt(1,board[0].length-2);

     // If the cell is empty place a mine there and count
     // it as placed. If the cell is not empty the loop
     // will repeat and a new cell will be tried.
     if (board[row][col] == '_')
     {
  board[row][col] = '*';
  minesPlaced++;
     }
     }
    }
         static void placeMines(int[][] mineBoard, int numMines)
         {

    // Mark all of the cells on the mineBoard as empty.
        for (int row=0; row < mineBoard.length; row++) {
            for (int col=0; col < mineBoard[0].length; col++) {
                mineBoard[row][col] = '_';
        }
    }
   

        

       
     }
    }



    

     /*    if(rows<3||columns<3)
         {
             System.out.println("At least 3 rows and 3 columns on board");
         }
         //double p = Double.parseDouble(args[2]);
    
         boolean[][] bombs = new boolean[M+2][N+2];
         for (int i = 1; i <= M; i++)
             for (int j = 1; j <= N; j++)
                 bombs[i][j] = (Math.random() < p);

        for (int i = 1; i <= M; i++) {
             for (int j = 1; j <= N; j++)
                 if (bombs[i][j]) System.out.print("* ");
                 else             System.out.print(". ");
             System.out.println();
         }

        int[][] sol = new int[M+2][N+2];
         for (int i = 1; i <= M; i++)
             for (int j = 1; j <= N; j++)
                 // (ii, jj) indexes neighboring cells
                 for (int ii = i - 1; ii <= i + 1; ii++)
                     for (int jj = j - 1; jj <= j + 1; jj++)
                         if (bombs[ii][jj]) sol[i][j]++;

        System.out.println();
         for (int i = 1; i <= M; i++) {
             for (int j = 1; j <= N; j++) {
                 if (bombs[i][j]) System.out.print("* ");
                 else             System.out.print(sol[i][j] + " ");
             }
             System.out.println();
         }

    }
}
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote