Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVAAAAAAAAA can somebody help me write/ edit the testing samples for testtakeShot()??? So far.. I have .. public static void testTakeShot () { char[][] board

JAVAAAAAAAAA

can somebody help me write/ edit the testing samples for testtakeShot()???

So far.. I have ..

public static void testTakeShot() { char[][] board = new char [5][5]; board = Battleship.initBoard(board[y][x]); // wanted to call initBoard() to fill it with water characters int x, y; boolean res; int numTests = 2; int passed = numTests; board[y][x] = Config.HIT_CHAR; if (res = Battleship.takeShot(board, x, y) != 3) { System.out.println("FAILED: Battleship.TakeShot() != 3, but "+ res); passed --; } board[y][x] = Config.WATER_CHAR;

if (res = Battleship.takeShot(board, x, y) != 2) { System.out.println("FAILED: Battleship.TakeShot() != 2, but "+ res); passed --; }

corresponding to

/** * Checks the state of a targeted cell on the game board. This method does not change the * contents of the game board. * * @return 3 if the cell was previously targeted. 2 if the shot would be a miss. 1 if the shot * would be a hit. -1 if the shot is out-of-bounds. */

public static int takeShot(char[][] board, int x, int y) {

if (board[y][x] == Config.HIT_CHAR || board[y][x] == Config.MISS_CHAR) { return 3; }

if (board[y][x] == Config.WATER_CHAR) { return 2; }

if (board[y][x] != Config.WATER_CHAR && board[y][x] != Config.HIT_CHAR && board[y][x] != Config.MISS_CHAR) { return 1; }

if (x < 0 || x > board[y].length || y < 0 || y > board.length) { return -1; }

return 0; }

for Config values

public static final char WATER_CHAR = '~'; // Water character (not yet targeted) public static final char HIT_CHAR = '*'; // Hit character public static final char MISS_CHAR = '@'; // Miss character

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

3rd Edition

0760049041, 978-0760049044

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago