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

JAVA HELPPPPPPPPPPPPP /** * Checks the state of a targeted cell on the game boar

ID: 3914416 • Letter: J

Question

JAVA HELPPPPPPPPPPPPP

/**
     * 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) {
        //FIXME
        return 0;
    }

Explanation / Answer

public static int takeShot(char[][] board, int x, int y) { if(board == null || x < 0 || board.length >= x || y < 0 || y >= board[x].length) { return -1; } char value = board[x][y]; if(value == Config.HIT_CHAR) { return 3 } else if(value == Config.WATER_CHAR) { return 2; } else { return 1; } }