SE450: Homework [41/41] ![]() ![]() ![]() |
Goal: To extend your Flight class to provide more functionality, to get familiar with the canonical form of classes, and to get familiar with JUnit - you will write the JUnit unit tests to prove that your code works.
Read Chapter 3 of Joshua Bloch's Effective Java. It will help you as you do the homework assignment this week. You can also refer to Jia Chapter 6.
Take your existing Flight class from hw3. Put it
in the package se450.<studentid>.hw4.
Implement the java.lang.Comparable interface in your
Flight class. Override the compareTo
method in this interface so that Flightss are sorted
properly. Proper sorting should be such that the following
is true:
Also write an equals
method for Flight. A Flight is
equal to another if they have the same Airline and Flight number
Write a test using JUnit which proves that your Comparable
implementation and equals function actually works.
You should
create at least three (maybe more)
Flight objects in your
setUp method. They should be stored in an
array (or Collection) of Flight objects. Have your test sort
the code using one of the Arrays.sort or
Collections.sort methods.
To prove that your equals methods work,
make sure you meet the contract, i.e. you support the
reflexive, symmetric, transitive, consistent, and null
reference properties of the equals method. Your unit test
for equals should exercise all of these properties. See chapter 3
of Block, the JavaDoc for Object.equals(), and 6.3.2 of
Jia for help.
Due next Monday at 5:30 PM.