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

Hello, I have to test my battleship, but I don\'t know how to start. I don\'t un

ID: 3916463 • Letter: H

Question

Hello, I have to test my battleship, but I don't know how to start. I don't understand what I do. Please help me how I can start, and how can I test my battleship?

Milestone 2: Placing Ships

1.

Best practice:

?

Start by writing the tests.

a.

Using the

?

testCoordAlphaToNum

?

method as template, write test methods with at least 2

tests in your test bench to test the

?

checkWater

?

and

?

placeShip

?

methods.

b.

OPTIONAL:

?

This is not required for the BP1 assignment, but ideally you would also create test

methods for

?

addShip

?

,

?

printBoard

?

, and

?

placeRandomShip

?

. Some of these methods

require a Scanner object and a Random object. To do the automated testing, you can create a

Scanner object from a String and a Random object from a specific seed.

2.

In this milestone, you will implement the methods:

?

checkWater, placeShip,

placeRandomShip, printBoard,

?

and

?

addShip.

?

The suggested approach is as follows:

a.

First implement

?

checkWater

?

.

i.

Use the test bench to check your method.

ii.

Once it passes your test bench, submit to zyBooks to see if you pass zyBooks test 1.

b.

Then, implement

?

placeShip

?

, use the test bench to check your method, and submit to zyBooks

to see if you pass zyBooks test 2.

c.

Then, implement

?

placeRandomShip

?

, and submit to zyBooks to see if you pass zyBooks test

3.

d.

Finally, implement

?

printBoard,

?

and

?

addShip

?

. If you implemented tests, use your test bench

to test.

3.

With the supporting methods written, you can update the main method to place ships on the game

boards. For Milestone 2, an algorithm for the main method is:

Begin the play again loop

?

Call

?

promptInt

?

for the

?

“board height”

?

, where the minimum value is

Config.MIN_HEIGHT

?

and the maximum value is

?

Config.MAX_HEIGHT

?

.

?

Call

?

promptInt

?

for the

?

“board width”

?

, where the minimum value is

?

Config.MIN_WIDTH

and the maximum value is

?

Config.MAX_WIDTH, followed by a newline.

?

Using the values read in for the height and the width, create the three 2d arrays required (see

main method header for more details) and initialize them with

?

initBoard.

?

Call

?

promptInt

?

for the

?

“number of ships”

?

, where the minimum value is

Config.MIN_SHIPS

?

and the maximum value is

?

Config.MAX_SHIPS

?

.

?

For each ship (start the index of the ships from 1), call the

?

addShip

?

method.

?

If any

?

addShip

?

method call fails, prompt the user with

?

“Error adding ships. Restart

game? (y/n): “

?

, using the

?

promptChar

?

method.

?

Otherwise, if all the

?

addShip

?

method calls succeed, prompt the user with

?

“Would you like

to play again? (y/n): “

?

, using the

?

promptChar

?

method.

Exit the loop if the value of

?

promptChar

?

is not a

?

‘y’

4.

Submit your

?

Battleship.java

?

and

?

TestBattleship.java

?

files to zyBooks for feedback and grading. We

recommend you complete commenting and styling your code for each milestone as described in the

Program Grading section of this document. Your highest scoring results prior to 6:00pm or (11:59pm

with a 10% deduction)

?

Thursday, March 22nd

?

will be recorded as your grade for this weekly

milestone.

Note: We may use different values in the Config.java for testing.

Milestone 2 Sample run:

?

Milestone2.txt

?

(interleaved input and output) [

?

Milestone2In.txt

?

,

?

Milestone2Out.txt

?

Explanation / Answer

Rules of Battleship in Java Game

There is a 5x5 board, ie 25 blocks. There are 3 hidden ships (one in each block).

The objective of the game is figuring out where these ships are placed and hit them.

Every shot fired is said if you hit a ship. If you have wrong is told how many ships are in that row and that column.

The game only ends when you find and sink the 3 ships.

Legend pro user:

~: Water in the block. Still not been shot.

*: Shot fired, there's nothing there.

X: shot fired, there was a ship.

How to play Battleship in Java Game:

Each round, enter two numbers: the number of the row and column number where you want to give the shot.

Then just wait to see if hit some ship, or the hint.

To Java programmers:

The board is 5x5 integer. It is initialized with values ??'-1'.

Every shot, it is upgraded, depending on whether you hit or missed. These figures serve to show '~', '*' or 'X' for the user.

Also serve to display tooltips.

Labels of the board:

-1: No shot was given in that block (~)

0: the shot was given and there was no ship there (*)

1: The user shot and had a ship there (X)

Methods:

----------------------------------------------------------------------------------

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