Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

First, make a class to store the location of your battleships. 1. Create a class named Location with only 2 attributes, row and column. Add

First, make a class to store the location of your battleships. 1. Create a class named Location with only 2 attributes, row and column.

Add getters and setters for both attributes and

a constructor that accepts the row and column values as arguments and assigns them appropriately

written in java

Then, add a driver class (either in the same le or separately) to drive your game. In this class:

2. Build your game board. This is a 5 x 5 two-dimensional char array.

Initialize the board to store Os (capital letter o) for the open water.

3. Create an ArrayList capable of storing Location objects (see step 1).

4. Using an object of the Random class, generate random row and column values for 3 battle ships. Create corresponding Location objects and append these objects to the ArrayList.

5. The user gets 4 attempts to guess where your battleships are. For each attempt, do the following: (a) Tell them how many attempts remain

(b) Tell them how many battleships remain

(c) Allow the user to make a guess, then: i. Check their guess against the boundaries of the board, if it is outside of the boundaries, display an appropriate message ii. Check the guess against cells already marked with an asterisk (indicating a battleship) or an X (indicating a miss), display a message to tell the user that theyve already guessed that location iii. Check the guess against all battleship locations in the ArrayList. If they guess correctly:

Remove that location from the ArrayList

Mark the location on the board with an asterisk

Display an appropriate message

iv. Otherwise, mark the guessed location with an X and display a message telling the user they have missed your battleship

(d) Print the board

(e) Decrement the number of turns

After all guesses have been made, if there are still battleships remaining, mark all of them on the board with an asterisk, display a message stating the game is over and reprint the board

Test your game!

Make sure correct and incorrect guesses work appropriately according to the above instructions. Take a screenshot of your successful game play

written in java.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions