CSC 217 Lab 03: Implement Comparable
in Student
Since the updated requirements state that Student
s must be stored in the directory in sorted order by last name, first name, and then unity id, you need to define the functionality for ordering Student
s. The SortedList
implementation requires that elements implement the Comparable
interface so that elements are added to the list in sorted order.
Implement Comparable
Interface
Add the statement implements Comparable<Student>
to the Student
class header.
The Comparable
interface is a generic interface, which means that a type must be specified when used. Since you are implementing Comparable
in Student
, the compared type is Student
and that is used as the generic type.
There will be a compiler error after adding the implements
statement and importing Comparable
. Use Eclipse’s Quick Fix to add the unimplemented method compareTo()
to Student
. The method signature should be:
public int compareTo(Student s)
Test compareTo()
Test that the compareTo()
method works correctly by adding a new test method to StudentTest
. Student
s should be ordered by last name, then first name, then their unity id. Use the documentation for the Comparable.compareTo()
method to write tests for Student.compareTo()
. Your tests will initially fail.
Implement compareTo()
Implement the compareTo()
method to pass your unit tests. You may need to iterate on the tests and implementation until you are done.
Run your Tests
Run your tests instrumented for coverage. Make sure that your tests execute at least 80% of the statements in Student
and that there are no regressions in functionality due to adding the new compareTo()
method.
Javadoc your Code
Make sure that you update the Javadoc in the Student
and StudentTest
classes.
Run CheckStyle to ensure that your Javadoc has all elements.
We do expect that all test classes are commented!
Push to GitHub
Push your PackScheduler
project to GitHub
- Add the unstaged changes to the index.
- Commit and push changes. Remember to use a meaningful commit message describing how you have changed the code.
Reminder: Staging and Pushing to GitHub
GitHub Resources:
Check Jenkins
Make sure that you have a job and it’s pulling from GitHub.
Your project will have a red ball. That is because you have not yet completed some of the refactorings that the teaching staff tests will expect. Therefore, the teaching staff tests are unable to compile against your code.
Reminder: Interpreting Jenkins
Check the following items on Jenkins for your last build and use the results to estimate your grade: