Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA-- toCharacter doesn't work in these loops- how can i fix that? /** * Places a ship into a game board. The coordinate passed in

JAVA-- "toCharacter" doesn't work in these loops- how can i fix that?

/**

* Places a ship into a game board. The coordinate passed in the parameters xcoord and ycoord

* represent the top-left coordinate of the ship. The ship is represented on the game board by

* the Character representation of the ship id. (For this method, you can assume that the id

* parameter will only be values 1 through 9.)

*

* @param board The game board to search.

* @param xcoord The x-coordinate of the top-left cell of the ship.

* @param ycoord The y-coordinate of the top-left cell of the ship.

* @param len The length of the ship.

* @param dir true if the ship will be vertical, otherwise horizontal.

* @param id The ship id, assumed to be 1 to 9.

* @return false if the ship goes out-of-bounds of the board, true otherwise.

*/

public static boolean placeShip(char board[][], int xcoord, int ycoord, int len, boolean dir,

int id) {

if (dir == true) {

for(int i = ycoord; i < ycoord+len; i++) {

board[i][xcoord] = Character.toCharacter(id);

{

return false;

}

}

}

else {

for(int i = xcoord; i < xcoord+len; i++) {

board[ycoord][i] = Character.toCharacter(id);

return false;

}

}

}

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

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions