SE450: Homework [23/24] ![]() ![]() ![]() |
Read Jia chapter 7, 9, and 10.1-10.2
Goal: to become familiar with the Java assertion facility and the design by contract concepts.
Your job is to implement DBC on new code you will write using Java assertions.
Add a new class to your previous homework assignments. This time you will implement a class called Airport. An Airport will consist of Runways (basically queues), and Gates.
The Airport class should have methods to set/get the Name (the code), the number of runways, add and remove Flights. You should also be able to get the Flights as a List. An airport should never be allowed to add a Flight that is already going to that Airport, or remove a flight that isn't currently at that airport, or have more flights than gates. It also should not allow null parameters in any of its functions. Your job is to write good pre and post conditions, and an invariant to ensure that these conditions hold true. Assume a very simple airport, where each flight goes to one gate, no gates are shared, and all flights happen in the same day.
Follow the six steps of the DBC methodology.
Your job is to implement an invariant method, preconditions for each command, and postconditions for each derived query. Use the java assertion facility for assertions, use an IllegalArgumentException (or a similar RuntimeException) for exceptions. Put the javadoc extensions (@invariant, @pre, and @post) in the right places with the right java code to show the condition.
Write a JUnit test called AirportTest
that shows that
the contracts of the methods can't be violated. You can do this by
putting each call around a try block that catches an Exception
that you expect to be thrown. If it fails, then catch the exception for
a successful test. If it doesn't fail, then fail the test. See last
week's notes for an example.
Submit
a ZIP
file that contains all java
files and
grader.txt
. The files should be in the same
package as you have used for your previous homework
assignments, except the package for this assignment will be
hw5 (i.e. se450.student.hw5).
You can use the grader.txt
file from the
previous homework.
Due Monday, February 17th at 5:30 PM.