Question: I cannot get this code to work in IntelliJ package com.company; import java.util.*; public class Main { public static void main(String[] args) { public class

I cannot get this code to work in IntelliJ

package com.company; import java.util.*; public class Main { public static void main(String[] args) { public class Battleship { public static char board[][] = new char[10][10]; public static void printBoard() { for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { if(board[i][j] == 'E') System.out.print(' '); else System.out.print(board[i][j]); } System.out.println(); } } public static void hide(char ship, int length, int row, int column, char orientation) { if(orientation == 'V') { for(int l = 0; l < length; l++) board[row + l][column] = ship; } else if(orientation == 'H') { for(int l = 0; l < length; l++) board[row][column + l] = ship; } } public static void main(String[] args) { for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) board[i][j]='E'; } Scanner scanner = new Scanner(System.in); int row, column; char orientation; System.out.println("Current board is:"); printBoard(); System.out.print("Enter the row and column of the beginning of the Aircraft carrier(5 length): "); row = scanner.nextInt(); column = scanner.nextInt(); System.out.print("Enter the orientation of the aircraft carrier (H for horizontal, V for vertical): "); orientation = scanner.next().charAt(0); hide('A', 5, row, column, orientation); System.out.println("Current board is:"); printBoard(); System.out.print("Enter the row and column of the beginning of the Battleship(4 length): "); row = scanner.nextInt(); column = scanner.nextInt(); System.out.print("Enter the orientation of the battleship (H for horizontal, V for vertical): "); orientation = scanner.next().charAt(0); hide('B', 4, row, column, orientation); System.out.println("Current board is:"); printBoard(); System.out.print("Enter the row and column of the beginning of the Submarine(3 length): "); row = scanner.nextInt(); column = scanner.nextInt(); System.out.print("Enter the orientation of the submarine (H for horizontal, V for vertical): "); orientation = scanner.next().charAt(0); hide('S', 3, row, column, orientation); System.out.println("Current board is:"); printBoard(); System.out.print("Enter the row and column of the beginning of the Destroyer(3 length): "); row = scanner.nextInt(); column = scanner.nextInt(); System.out.print("Enter the orientation of the Destroyer (H for horizontal, V for vertical): "); orientation = scanner.next().charAt(0); hide('D', 3, row, column, orientation); System.out.println("Current board is:"); printBoard(); System.out.print("Enter the row and column of the beginning of the Patrol boat(2 length): "); row = scanner.nextInt(); column = scanner.nextInt(); System.out.print("Enter the orientation of the patrol boat (H for horizontal, V for vertical): "); orientation = scanner.next().charAt(0); hide('P', 2, row, column, orientation); System.out.println("Current board is:"); printBoard(); scanner.close(); } } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!