Хорошо, поэтому я должен разместить на борту линкор, используя исключения, чтобы убедиться, что правила не нарушены. Тем не менее, когда я пытаюсь вызвать функцию, я получаю это:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type Exception
at BattleshipBoard.main(BattleshipBoard.java:135)
Не уверен на 100%, что я делаю неправильно, если бы вы, ребята, могли определить, что не так, и связанное с этим правило, которое я, по-видимому, нарушаю, было бы очень признательно.
вот соответствующий код:
public void placeShip(int startCol, int startRow, int endCol, int endRow)
throws Exception {
if(startCol > numCols) {
throw new Exception("0");
}
if(startCol < 0 ) {
throw new Exception("Out of bounds, less than 1(startCol)");
}
if (startRow > numRows) {
throw new Exception("Out of bounds, Greater then numRows");
}
if (startRow < 0) {
throw new Exception("Out of bounds, less than 1 (startRow)");
}
if((startCol != endCol) && (startRow != endRow)){
throw new Exception("Diag");
}
if(board[i][j] == 1){
throw new Exception("Overlap");
}
if (startCol == endCol){
for (i = startCol; i <= endCol; i++ ){
board[i][j] = 1;
}
}
if (startRow == endRow){
for(j = startRow; j <= endRow; j++){
board[i][j] = 1;
}
}
}
public static void main(String args[]) {
// You may leave this empty
BattleshipBoard b = new BattleshipBoard(10, 10);
b.placeShip(0, 0, 3, 0);
}