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

IMPORTANT -HAS TO BE IN JAVA -CANNOT USE java.util.ArrayList for the ARRAYS -CAN

ID: 3750429 • Letter: I

Question

IMPORTANT

-HAS TO BE IN JAVA

-CANNOT USE java.util.ArrayList for the ARRAYS

-CANNOT USE java.util.ArrayList for the ARRAYS

Battleship In this assignment, you will write a program to play a game of Battleship against the computer. Our simplified version of the game will be played on a single 8 by 8 grid. Before the actual game, each player secretly places 6 ships and 4 grenades on the grid. Ships and grenades are a single position on the grid. The position of these ships and grenades are of course hidden from the opponent. Once both players have placed their ships and grenades, the actual game starts. Each player, in turn, "shoots a rocket" on the grid (i.e. calls a position). If the rocket (the position called) falls on a position where there is nothing, then nothing happens, and the other player can shoot his/her rocket. -If the rocket falls on a coordinate where the opponent (or the player) has a grenade, then the player loses a turn, and next time, the opponent will play twice in a row -If the rocket falls on a coordinate where the opponent (or the player...) has a ship, then that ship sinks -If the rocket falls on a coordinate that has been called before, regardless of what was there before, nothing happens. (So for example, a grenade can only explode once) The goal of the game is to sink all of your opponent's ships before your opponent sinks yours. For the sake of simplicity, you can assume that ships and grenades cannot overlap. So you cannot have 2 grenades on the same position, have 2 ships on the same position, or have a grenade on a ship For example, let's consider the following grid Here, one player (identified in black) has his/her 6 ships at positions Al, Gl, A4, C4, G4 and A6 and 4 grenades at positions Di, B6, B7 and H6. The other player has his/her ships at H2, , E3, H4, E5 and C8 and 4 grenades at positions HI, B2, C6 and H7 If black starts the game and "shoots a rocket" at position D2 then nothing happens, and we have the following grid. S G

Explanation / Answer

Please run this program and check as per you inpout if still you need any modification or addition in it. Do let me know in the comments and i will amke that for you . import java.util.Random; import java.util.Scanner; public class Game { public static void main(String[] args) { System.out.println("Welcome to the Battle Field."); System.out.println("Please enter all alphabets in UPPER CASE."); System.out.println("==============================================================="); Random r1=new Random(); int rNum1=0; int rNum2=0; Scanner sc=new Scanner(System.in); String[][] computerGrid=new String[9][9]; String[][] humanGrid=new String[9][9]; String[][] inputgameGridArr=new String[9][9]; int x=0; int y=0; boolean invalid=true; String input=""; for(int i=1;i