This is a testing program for the Battleship game. Of course, you will need to add more tests.

public class Game {
    public static void main(String [] args) {
	Board board = new Board();
	if (!board.addShip("Carrier",5,'a',3,true)) {
	    System.out.println("Failed to add carrier");
	}

	if (!board.addShip("Battleship",4,'e',5,false)) {
	    System.out.println("Failed to add battleship");
	}
	System.out.println(board.shot('a',3));
	System.out.println(board.shot('b',3));
	System.out.println(board.shot('a',5));
	System.out.println(board.shot('d',3));
	System.out.println(board.shot('f',5));
	System.out.println(board.shot('e',5));
	System.out.println(board.shot('h',5));
	System.out.println(board.shot('g',5));

	if (!board.addShip("Carrier",5,'h',3,false)) {
	    System.out.println("Failed to add carrier");
	}
	System.out.println(board.shot('g',11));
	System.out.println(board.shot('z',3));

	board.printBoard();
	board.printShips();
    }
}
You may also download classes Board.class and Ship.class to run the program. Compare your results to those produced by the sample program.
This page is a part of the course CSci 1211 at UMM.