Question: *JAVA program* 1. Battleship Guessing Game Write a simple 2D Guessing Game program that will allow the user to guess the row and column that
*JAVA program*


1. "Battleship" Guessing Game Write a simple 2D Guessing Game program that will allow the user to guess the row and column that the number "O" (the battleship) is in. If the row and column guess is correct, the computer will display a "You Sunk my Battleship!" message. If the row and column guess is incorrect, the computer will tell the user how many rows and columns the guess is off by. For example if the number to be guessed is in (0,0) and the user guesses (3, 4), the computer will tell the user he/she is off by 3 rows and 4 columns. If you wish, you may limit the user to a certain number of guesses to increase the difficulty level. Complete the following tasks for your guessing game (feel free to add your own features that maintain the spirit of the game) a. Create a 2D array called gameBoard of type int. Use dialog boxes to ask the user how many rows and columns he/she wants for the game. b. Use a for loop to fill the 2D array with random numbers between 1 and 100. c. Use Math.random() to pick a random row and random column to place the number 0 (Battleship) in (this will be the number that the user must attempt to find). Hint: call Math.random() twice to generate two random numbers...one for the row and one for the column. Be sure not to pick rows and/or columns that are out of bounds! d. Print the 2D array in rectangular format using an X to represent each number in the 2D array, effectively "hiding the numbers in the 2D array. e. Use a dialog box to ask the user for a row and column to use as their guess e. Use a dialog box to ask the user for a row and column to use as their guess to find the "battleship". f. If the guess is correct, reply with a message confirming the win! (e.g. "You Sunk My Battleship!") g. If the guess is incorrect, replay with a message telling the user how many rows and how many columns he/she is off by (see the example above). h. Reprint the array, placing a M for Miss!" in place of the "X" to show that this location has already been picked. i. Repeat steps (e) through (h) until the number "O" is found or until all locations have been checked (unless you choose the limit the number of guesses)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
