Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Train Dispatch System
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
Johanne Fixdal
Train Dispatch System
Commits
6a08d191
Commit
6a08d191
authored
1 year ago
by
Johanne Fixdal
Browse files
Options
Downloads
Patches
Plain Diff
Updated Train Departure, input for departure time is split to LocalTime.of(int hours, int minutes)
parent
9efe63b7
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/TrainDeparture.java
+20
-25
20 additions, 25 deletions
src/main/java/edu/ntnu/stud/TrainDeparture.java
src/test/java/edu/ntnu/stud/TrainDepartureTest.java
+2
-2
2 additions, 2 deletions
src/test/java/edu/ntnu/stud/TrainDepartureTest.java
with
22 additions
and
27 deletions
src/main/java/edu/ntnu/stud/TrainDeparture.java
+
20
−
25
View file @
6a08d191
...
...
@@ -7,7 +7,9 @@ import java.util.ArrayList;
* Entity class for train departures.
*/
public
class
TrainDeparture
{
private
LocalTime
departureTime
=
LocalTime
.
MIN
;
private
final
LocalTime
departureTime
;
private
int
hour
;
private
int
minutes
;
private
final
String
line
;
private
final
String
trainNumber
;
private
final
String
destination
;
...
...
@@ -15,21 +17,24 @@ public class TrainDeparture {
private
LocalTime
delay
;
private
static
LocalTime
clock
=
LocalTime
.
MIN
;
// delay-method is not final, due to changes
/**
*
* @param departureTime
* @param hour
* @param minutes
* @param line
* @param trainNumber
* @param destination
* @throws IllegalArgumentException
*/
public
TrainDeparture
(
LocalTime
departureTime
,
String
line
,
String
trainNumber
,
String
destination
)
throws
IllegalArgumentException
{
public
TrainDeparture
(
int
hour
,
int
minutes
,
String
line
,
String
trainNumber
,
String
destination
)
throws
IllegalArgumentException
{
if
(
departureTime
==
null
){
throw
new
IllegalArgumentException
(
"A departure time is required"
);
if
(
hour
<
0
||
hour
>
23
){
throw
new
IllegalArgumentException
(
"Invalid hour"
);
}
if
(
minutes
<
0
||
minutes
>
59
)
{
throw
new
IllegalArgumentException
(
"Invalid minutes"
);
}
if
(
line
==
null
){
throw
new
IllegalArgumentException
(
"A line input is required"
);
}
...
...
@@ -40,7 +45,7 @@ public class TrainDeparture {
throw
new
IllegalArgumentException
(
"A destination is required"
);
}
this
.
departureTime
=
departureTime
;
departureTime
=
LocalTime
.
of
(
hour
,
minutes
)
;
this
.
line
=
line
;
this
.
trainNumber
=
trainNumber
;
this
.
destination
=
destination
;
...
...
@@ -51,6 +56,8 @@ public class TrainDeparture {
/**
* Get methods from train departure attributes
*
* @return
*/
public
LocalTime
getDepartureTime
()
{
return
departureTime
;
...
...
@@ -80,7 +87,6 @@ public class TrainDeparture {
}
/**
* set method for train departure attribute "track"
* @param track
...
...
@@ -97,25 +103,14 @@ public class TrainDeparture {
public
void
setDelay
(
LocalTime
delay
)
{
this
.
delay
=
delay
;
}
public
void
setClock
(
LocalTime
clock
)
{
this
.
clock
=
clock
;
}
/**
* Print out informationBoard
* set method for clock
* @param clock
*/
public
String
informationBoard
()
{
System
.
out
.
println
(
"---------- Train departure ----------------"
);
System
.
out
.
println
(
"Departure time: "
+
getDepartureTime
());
System
.
out
.
println
(
"Train number: "
+
getTrainNumber
());
System
.
out
.
println
(
"Train line: "
+
getLine
());
System
.
out
.
println
(
"Track: "
+
getTrack
());
System
.
out
.
println
(
"Destination: "
+
getDestination
());
System
.
out
.
println
(
"Delay: "
+
getDelay
());
return
" "
;
public
void
setClock
(
LocalTime
clock
)
{
this
.
clock
=
clock
;
}
@Override
public
String
toString
()
{
return
"---------------TrainDeparture-----------------------"
...
...
This diff is collapsed.
Click to expand it.
src/test/java/edu/ntnu/stud/TrainDepartureTest.java
+
2
−
2
View file @
6a08d191
...
...
@@ -7,7 +7,7 @@ import java.time.LocalTime;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
public
class
TrainDepartureTest
{
TrainDeparture
test
=
new
TrainDeparture
(
LocalTime
.
of
(
12
,
00
)
,
"R2"
,
"222"
,
"Oslo"
);
TrainDeparture
test
=
new
TrainDeparture
(
12
,
00
,
"R2"
,
"222"
,
"Oslo"
);
@Nested
class
getTest
{
@Test
...
...
@@ -20,7 +20,7 @@ public class TrainDepartureTest {
}
@Nested
class
setTest
{
TrainDeparture
test
=
new
TrainDeparture
(
LocalTime
.
of
(
12
,
00
)
,
"R2"
,
"222"
,
"Oslo"
);
TrainDeparture
test
=
new
TrainDeparture
(
12
,
00
,
"R2"
,
"222"
,
"Oslo"
);
int
newTrack
=
3
;
LocalTime
newDelay
=
LocalTime
.
of
(
00
,
05
);
@Test
...
...
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