Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static boolean allTheKnightsAreSafe(ArrayList<String> coordinateStrings,

ID: 3897113 • Letter: P

Question

public static boolean allTheKnightsAreSafe(ArrayList<String> coordinateStrings, int boardSize) Description: Given an ArrayList of coordinate strings representing the locations of the knights on a boardSize × boardSize chess board, return true if none of the knights can attack one another. Otherwise, return false.
Parameter Restrictions: boardSize will be a positive integer less than or equal to Integer.MAX_VALUE. boardSize describes both the length and width of the square board. (So, if boardSize = 8, then we have an 8 × 8 board.) coordinateStrings will be non-null, and any strings within that ArrayList will follow the format described above for valid coordinates on a boardSize × boardSize board. Each coordinate string in the ArrayList is guaranteed to be unique; the same coordinate string will never appear in the list more than once.
Output: This method should not print anything to the screen. Printing stray characters to the screen (including newline characters) is a leading cause of test case failure.

Explanation / Answer

public static boolean allTheKnightsAreSafe(ArrayList coordinateStrings, int boardSize) { // First we create our alphabet HashMap and set a value to each letter. Map map; map = new HashMap(); for(int i=1; i