Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!