diff --git a/src/main/java/edu/ntnu/stud/Scan.java b/src/main/java/edu/ntnu/stud/Scan.java index 8bb6877ea85323b6d65625c561d324e6b6162cc7..ecc839cf91ac621bce1db86e858216ba3a47b70d 100644 --- a/src/main/java/edu/ntnu/stud/Scan.java +++ b/src/main/java/edu/ntnu/stud/Scan.java @@ -11,7 +11,7 @@ import java.util.Scanner; * departure times, delays, destinations, lines, menu choices, and yes/no switches. * It also includes utility methods for validating input based on specific criteria. * - * @author Your Name + * @author 10018 * @version 1.0 * @since 0.1 */ @@ -166,7 +166,8 @@ public class Scan { while (!validLine) { line = scanner.nextLine(); - if (validateNotEmpty(line) || !(validateLettersAndDigitsOnly(line) && validateStringLength(line))) { + if (validateNotEmpty(line) || !(validateLettersAndDigitsOnly(line) + && validateStringLength(line))) { System.out.println("Line can only contain letters and numbers, max 5 characters"); System.out.println("and cannot be empty."); System.out.println(PLEASE_TRY_AGAIN); @@ -237,12 +238,19 @@ public class Scan { return result; } + /** + * Validates whether the entered string is empty. + * + * @param string The string to be verified. + * @return True if the string is empty. + * False otherwise. + */ public boolean validateNotEmpty(String string) { return string.isEmpty(); } /** - * Validates whether the entered string is empty and only consists of positive integers. + * Validates whether the entered string only consists of positive integers. * * @param string The string to be verified. * @return True if the string is not empty and only consists of digits. @@ -253,18 +261,18 @@ public class Scan { } /** - * Validates whether the entered string empty and consists of maximum 5 characters. + * Validates whether the entered string consists of maximum 5 characters. * * @param string The string to be validated. * @return True if the string is not empty and has 5 or fewer characters. * False otherwise. */ public boolean validateStringLength(String string) { - return string.length() <= 5; + return string.length() <= 5; } /** - * Validates whether the entered string is empty and only consists of letters. + * Validates whether the entered string only consists of letters. * * @param string The string entered to be validated. * @return True if the string is not empty and only consists of letters. @@ -275,7 +283,7 @@ public class Scan { } /** - * Validates whether the entered string is empty and only consists of letters and digits. + * Validates whether the entered string only consists of letters and digits. * * @param string The string entered to be validated. * @return True if the string is not empty and only consists of letters. diff --git a/src/main/java/edu/ntnu/stud/TrainDeparture.java b/src/main/java/edu/ntnu/stud/TrainDeparture.java index 41c82df8a0d3bcf82191788291605c3ad904a1f2..8832e14d93d043af1820cfc41bf2f8e5106e2c03 100644 --- a/src/main/java/edu/ntnu/stud/TrainDeparture.java +++ b/src/main/java/edu/ntnu/stud/TrainDeparture.java @@ -56,15 +56,15 @@ public class TrainDeparture { * string is blank. * * @param string is the string being verified. - * @param parameterName is the name of the String being verified. Used in the exception message + * @param parameter is the name of the String being verified. Used in the exception message * if the Ill.Arg.Exc is being thrown. * @throws IllegalArgumentException if the String is either "" or consists only of * whitespace, as it does not give any information. */ - private void verifyNotEmpty(String string, String parameterName) + private void verifyNotEmpty(String string, String parameter) throws IllegalArgumentException { if (string.isBlank()) { - throw new IllegalArgumentException("The string for the parameter '" + parameterName + throw new IllegalArgumentException("The string for the parameter '" + parameter + "' was a blank string. Please retry registration."); } }