From 12668db4086e29f74a2152075e1b79b81eae77e9 Mon Sep 17 00:00:00 2001 From: Imron Date: Wed, 16 Feb 2022 14:43:33 +0100 Subject: [PATCH 1/2] add flight schedule --- .../hs/fulda/de/ci/exam/project/Flight.java | 18 +++++++-- .../de/ci/exam/project/FlightInstance.java | 39 +++++++++++++++++++ .../de/ci/exam/project/FlightStatus.java | 5 +++ .../fulda/de/ci/exam/project/FlightTest.java | 20 +++++----- 4 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java index 073d93b..ef70d40 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java @@ -1,7 +1,6 @@ package hs.fulda.de.ci.exam.project; import java.util.HashSet; -import java.util.LinkedList; public class Flight { String flightNumber; @@ -21,12 +20,25 @@ public class Flight { return this.flightInstances; } + public FlightInstance getFlightInstance(FlightInstance fi){ + for (FlightInstance obj : flightInstances) { + if (obj.equals(fi)) + return obj; + } + return null; + } + public boolean cancel() { return true; } - public boolean addFlightSchedule() { - return true; + public boolean addFlightSchedule(FlightInstance fi) { + flightInstances.add(fi); + if (flightInstances.contains(fi)) { + System.out.println("Flight instance is added"); + return true; + } + return false; } public String getFlightNumber() { diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java index 50672a7..edbcaaf 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightInstance.java @@ -1,4 +1,43 @@ package hs.fulda.de.ci.exam.project; +import java.sql.Time; + public class FlightInstance { + Time departureTime; + String gate; + FlightStatus status; + + public FlightInstance(Time departureTime, String gate, FlightStatus status) { + this.departureTime = departureTime; + this.gate = gate; + this.status = status; + } + + public FlightInstance(){ + + } + + public Time getDepartureTime() { + return departureTime; + } + + public void setDepartureTime(Time departureTime) { + this.departureTime = departureTime; + } + + public String getGate() { + return gate; + } + + public void setGate(String gate) { + this.gate = gate; + } + + public FlightStatus getStatus() { + return status; + } + + public void setStatus(FlightStatus status) { + this.status = status; + } } diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java new file mode 100644 index 0000000..68aadf2 --- /dev/null +++ b/src/main/java/hs/fulda/de/ci/exam/project/FlightStatus.java @@ -0,0 +1,5 @@ +package hs.fulda.de.ci.exam.project; + +public enum FlightStatus { + Active, Scheduled, Delayed, Departed, Landed, InAir, Arrived, Cancelled, Diverted, Unknown +} diff --git a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java index d6efd42..424f074 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java @@ -2,9 +2,12 @@ package hs.fulda.de.ci.exam.project; import org.junit.jupiter.api.Test; +import java.sql.Time; import java.util.HashSet; -import static org.assertj.core.api.Assertions.*; +import static hs.fulda.de.ci.exam.project.FlightStatus.Active; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; class FlightTest { @@ -19,7 +22,7 @@ class FlightTest { Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140); Flight flight2 = new Flight("2", airport1_ist, airport_fr, 120); - FlightInstance fInstance1 = new FlightInstance(); + FlightInstance fInstance1 = new FlightInstance(new Time(12,45,00), "4E", Active); @Test void getInstances_no_instance_should_be_equal() { @@ -37,13 +40,12 @@ class FlightTest { } @Test - void cancel() { - // TODO: 26.01.22 discussion needed - } - - @Test - void addFlightSchedule() { - // TODO: 26.01.22 discussion needed + void addFlightScheduleShoudlAddFlightInstanceWithActiveStatus() { + boolean addInstance = flight1.addFlightSchedule(fInstance1); + assertTrue(addInstance); + FlightStatus result = flight1.getFlightInstance(fInstance1).getStatus(); + FlightStatus expected = Active; + assertThat(expected).isEqualTo(result); } @Test From 252216de6bc9104ea8884120eb727267a8ec8f2f Mon Sep 17 00:00:00 2001 From: Imron Date: Wed, 16 Feb 2022 14:50:05 +0100 Subject: [PATCH 2/2] flight cancellation --- .../hs/fulda/de/ci/exam/project/Flight.java | 18 +++++++++++++++--- .../fulda/de/ci/exam/project/FlightTest.java | 13 ++++++++++++- .../hs/fulda/de/ci/exam/project/Flight.class | Bin 2375 -> 3535 bytes .../de/ci/exam/project/FlightInstance.class | Bin 323 -> 1376 bytes .../fulda/de/ci/exam/project/FlightTest.class | Bin 4071 -> 5170 bytes 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java index ef70d40..4e6604d 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/Flight.java +++ b/src/main/java/hs/fulda/de/ci/exam/project/Flight.java @@ -2,6 +2,8 @@ package hs.fulda.de.ci.exam.project; import java.util.HashSet; +import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled; + public class Flight { String flightNumber; Airport departure; @@ -20,7 +22,7 @@ public class Flight { return this.flightInstances; } - public FlightInstance getFlightInstance(FlightInstance fi){ + public FlightInstance getFlightInstance(FlightInstance fi) { for (FlightInstance obj : flightInstances) { if (obj.equals(fi)) return obj; @@ -28,8 +30,18 @@ public class Flight { return null; } - public boolean cancel() { - return true; + public boolean cancel(FlightInstance fInstance1) { + if (flightInstances.contains(fInstance1)) { + for (FlightInstance obj : flightInstances) { + if (obj.equals(fInstance1)) { + obj.status = Cancelled; + System.out.println("Flight intance is cancelled"); + } + } + return true; + } + return false; + } public boolean addFlightSchedule(FlightInstance fi) { diff --git a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java index 424f074..17d0b9c 100644 --- a/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java +++ b/src/test/java/hs/fulda/de/ci/exam/project/FlightTest.java @@ -6,6 +6,7 @@ import java.sql.Time; import java.util.HashSet; import static hs.fulda.de.ci.exam.project.FlightStatus.Active; +import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -22,7 +23,7 @@ class FlightTest { Flight flight1 = new Flight("1", airport_fr, airport1_ist, 140); Flight flight2 = new Flight("2", airport1_ist, airport_fr, 120); - FlightInstance fInstance1 = new FlightInstance(new Time(12,45,00), "4E", Active); + FlightInstance fInstance1 = new FlightInstance(new Time(12, 45, 00), "4E", Active); @Test void getInstances_no_instance_should_be_equal() { @@ -48,6 +49,16 @@ class FlightTest { assertThat(expected).isEqualTo(result); } + @Test + void cancelingFlightShouldChangeActiveToCancelled() { + boolean addInstance = flight1.addFlightSchedule(fInstance1); + assertTrue(addInstance); + flight1.cancel(fInstance1); + FlightStatus result = flight1.getFlightInstance(fInstance1).getStatus(); + FlightStatus expected = Cancelled; + assertThat(expected).isEqualTo(result); + } + @Test void getFlightNumber() { assertThat(flight1.getFlightNumber()).describedAs("get flight number of the flight").isEqualTo("1"); diff --git a/target/classes/hs/fulda/de/ci/exam/project/Flight.class b/target/classes/hs/fulda/de/ci/exam/project/Flight.class index 7876b6beb186aa354847a166df6461ce280aea27..4e95dbfb6e7a70008e38422adfbe06a6ac7e2bfc 100644 GIT binary patch literal 3535 zcmb7HTUQfT6#fngnIsG%SFIq83IY*~w)Ub36+ucYplz&H?ZqJ($UvBh$%IO+z4xUr zeXYO17a!DBbk(la)#v_z{(=6BE?4b$<`NQ;g|f2d%$YO$^6hW$ea_^s|DOH<;4S!i*ot>2tGh60u`4c_z;)F zxDv%jxGLXW3*&kl{d}h2h5}7MUCbFvS$n>;x}X;X+GdxvH7$|T%%w!iE*R$0s6Zs6 z=e2@eD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