Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TrainDispatchSystem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Lundemo
TrainDispatchSystem
Commits
5092445f
Commit
5092445f
authored
1 year ago
by
Anders Lundemo
Browse files
Options
Downloads
Patches
Plain Diff
Final changes
parent
ac349091
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/edu/ntnu/stud/Scan.java
+15
-7
15 additions, 7 deletions
src/main/java/edu/ntnu/stud/Scan.java
src/main/java/edu/ntnu/stud/TrainDeparture.java
+3
-3
3 additions, 3 deletions
src/main/java/edu/ntnu/stud/TrainDeparture.java
with
18 additions
and
10 deletions
src/main/java/edu/ntnu/stud/Scan.java
+
15
−
7
View file @
5092445f
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
src/main/java/edu/ntnu/stud/TrainDeparture.java
+
3
−
3
View file @
5092445f
...
...
@@ -56,15 +56,15 @@ public class TrainDeparture {
* string is blank.
*
* @param string is the string being verified.
* @param parameter
Name
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
parameter
Name
)
private
void
verifyNotEmpty
(
String
string
,
String
parameter
)
throws
IllegalArgumentException
{
if
(
string
.
isBlank
())
{
throw
new
IllegalArgumentException
(
"The string for the parameter '"
+
parameter
Name
throw
new
IllegalArgumentException
(
"The string for the parameter '"
+
parameter
+
"' was a blank string. Please retry registration."
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment