Task 4 updated

This commit is contained in:
Immanuel Alvaro Bhirawa
2023-03-23 14:06:49 +11:00
parent c12d3c2efe
commit f2747a9582

View File

@@ -115,24 +115,27 @@ public class BlueLagoon {
*/ */
public static boolean isMoveStringWellFormed(String moveString) { public static boolean isMoveStringWellFormed(String moveString) {
// Split the initial string onto 2 parts, before " " and after " " // Split the initial string onto 2 parts, before " " and after " "
// The string will be split onto pieceType and Coords parts
String[] parts = moveString.split(" "); String[] parts = moveString.split(" ");
// if there's more than one " " after a spllit return false // if there's more than one " " after a split return false
if (parts.length != 2) return false; if (parts.length != 2) return false;
// Before " " (i.e. checking the pieceType) // Before " " (i.e. checking the pieceType. pieceType must be "S" or "T")
String pieceType = parts[0]; String pieceType = parts[0];
if (!pieceType.equals("S") && !pieceType.equals("T")) return false; if (!pieceType.equals("S") && !pieceType.equals("T")) return false;
// After " ", (checking the coords) // After " ", (checking the coords)
// The coords array will be split onto checking the row (before ",") and
// col cords (after ",")
String[] coords = parts[1].split(","); String[] coords = parts[1].split(",");
// Check if there's multiples "," // Check if there's multiples ","
if (coords.length != 2) return false; if (coords.length != 2) return false;
// Checks whether the row cords are digits or not and whether the digits fit into the interval // Checks whether the row cords are digits or not and whether the digits
// fit into the interval ( i.e. row and coll cannot be below 0 )
// will catch an error and return false if either row coords or col coords are not digits // will catch an error and return false if either row coords or col coords are not digits
if (coords[0].length() <= 2 || coords[1].length() <= 2) {
try { try {
int row = Integer.parseInt(coords[0]); int row = Integer.parseInt(coords[0]);
int col = Integer.parseInt(coords[1]); int col = Integer.parseInt(coords[1]);
@@ -141,7 +144,6 @@ public class BlueLagoon {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
return false; return false;
} }
}
return true; ///FIXME TASK 4. return true; ///FIXME TASK 4.
} }