Skip to content
Snippets Groups Projects
Commit 5092445f authored by Anders Lundemo's avatar Anders Lundemo
Browse files

Final changes

parent ac349091
No related branches found
No related tags found
No related merge requests found
......@@ -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,7 +261,7 @@ 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.
......@@ -264,7 +272,7 @@ public class Scan {
}
/**
* 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.
......
......@@ -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.");
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment