import java.util.Random; public class Ocean extends GoodOcean{ public void placeAllBoats(){ int n = 0; String orient; Random generator = new Random(); while(n != 1){ try{ int row = generator.nextInt(10); int col = generator.nextInt(10); int ori = generator.nextInt(2); if(ori == 1) orient = "vertical"; else orient = "horizontal"; this.placeBoat("aircraft carrier", orient, new Position(row, col)); n = 1; }catch(Exception e){ n = 0; } } n = 0; while(n != 1){ try{ int row1 = generator.nextInt(10); int col1 = generator.nextInt(10); int ori1 = generator.nextInt(2); if(ori1 == 1) orient = "vertical"; else orient = "horizontal"; this.placeBoat("battleship", orient, new Position(row1, col1)); n = 1; }catch(Exception e){ n = 0; } } n = 0; while(n != 1){ try{ int row2 = generator.nextInt(10); int col2 = generator.nextInt(10); int ori2 = generator.nextInt(2); if(ori2 == 1) orient = "vertical"; else orient = "horizontal"; this.placeBoat("cruiser", orient, new Position(row2, col2)); n = 1; }catch(Exception e){ n = 0; } } n = 0; while(n != 1){ try{ int row3 = generator.nextInt(10); int col3 = generator.nextInt(10); int ori3 = generator.nextInt(2); if(ori3 == 1) orient = "vertical"; else orient = "horizontal"; this.placeBoat("destroyer", orient, new Position(row3, col3)); n = 1; }catch(Exception e){ n = 0; } } n = 0; while(n != 1){ try{ int row4 = generator.nextInt(10); int col4 = generator.nextInt(10); int ori4 = generator.nextInt(2); if(ori4 == 1) orient = "vertical"; else orient = "horizontal"; this.placeBoat("submarine", orient, new Position(row4, col4)); n = 1; }catch(Exception e){ n = 0; } } } }