public class BattleshipTester public static void main(String[] args) // 1. Create ship objects Battleship submarine = new Battleship("Submarine", 4); Battleship carrier = new Battleship("Carrier", 10); // 2. Check initial positions System.out.println(submarine); System.out.println(carrier); // 3. Test: Safely move submarine (Increases position by 7) System.out.println("Submarine cleared to proceed"); submarine.move(true); System.out.println(submarine); // 4. Test: Unsafe to move carrier (Decreases position by 2) System.out.println("Carrier NOT cleared to proceed"); carrier.move(false); System.out.println(carrier); Use code with caution. Copied to clipboard
Print the positions again to ensure they changed by +5 and -5, respectively. 4. Common Pitfalls to Avoid 3.3.6 battleships move codehs
// Getters and Setters are essential for OOP public int getRow() return row; public int getCol() return col; Test: Safely move submarine (Increases position by 7) System
set_position(ship, ship_x, ship_y)
To complete the 3.3.6 exercise, you must add an if-else statement to the move method where position += 7 occurs when safeToMove is true, and position -= 2 occurs when it is false. public int getCol() return col