CSC216 Lab 01: Implement Student
The Student class represents an individual student record. The Student class is a “plain old java object” (POJO) consisting mostly of getters and setters. The setters do have some complexity. Note that some, but not all of the methods are provided to you. You will need to create the other methods to satisfy the design of the StudentDirectory functionality of PackScheduler.
Student State
A Student knows her first name (String), last name (String), id (String), email (String), password (String), and max credits (int). Create the fields for Student. All fields should be private.
Additionally, Student has a constant MAX_CREDITS that represents the maximum possible credits any student can have. Since the constant is useful in test cases, MAX_CREDITS is public and should be set to the value of 18. The constant MAX_CREDITS represents the max number of credits that any student in the system may have. The field maxCredits is the max credits that a specific student (e.g., this) may enroll in.
Note that the Student class does not hash the password. We expect that the password is passed in as a hashed value. The reason for this is that the password should be hashed as soon as possible after the user enters it. That means the class right behind the GUI, StudentDirectory will handle the hashing. You can assume that you will receive a hashed String for the password.
Student Constructors
Student has two constructors; one that has parameters for all fields the other that has parameters for all fields but max credits.
Student(String firstName, String lastName, String id, String email, String password, int maxCredits): calls the setters for each of the fields. If the setters throw anIllegalArgumentExceptionthe exception should pass through the constructor to the client. That means the constructor does NOT catch the exception. Just call the setters!Student(String firstName, String lastName, String id, String email, String password): calls the other constructor with the default max credits value of 18.
Student Getters
All getters for the Student fields are straight forward; they return the field. Use Source Code Generation to help you create the getters.
Student Setters
The setters are more complex because they check to make sure that the Student fields are not invalid as defined in the [Student Records Data Format] and in [Use Case 3: Load Student Directory] and [Use Case 5: Add Student to Student Directory]. If a value is invalid an IllegalArgumentException is thrown. Note taht you are not yet fully implementing Use Case 3 and 5. You’re creating functionality that will make the full implementation of these use cases easier in other parts of the program.
The Alternative Flows of [Use Case 5: Add Student to Student Directory] describe the string messages that should be used when constructing the IllegalArgumentException if there’s an error.
setFirstName(String firstName): throws anIllegalArgumentExceptionif the parameter is null or an empty string.setLastName(String lastName): throws anIllegalArgumentExceptionif the parameter is null or an empty string.setId(String id): throws anIllegalArgumentExceptionif the parameter is null or an empty string.setEmail(String email): throws anIllegalArgumentExceptionif:- the parameter is null or an empty string
- email doesn’t contain an ‘@’ character
- email doesn’t contain a ‘.’ character
- the index of the last ‘.’ character in the email string is earlier than the index of the first ‘@’ character (e.g., first.last@address would be invalid)
setPassword(String password): throws anIllegalArgumentExceptionif the parameter is null or an empty string.setMaxCredits(int maxCredits): throws anIllegalArgumentExceptionif the parameter is less than 3 or greater than 18.
Note that in the design, setId() is listed as a private method. This is because a Student’s id shouldn’t change after creation - it’s the unique identifier in the StudentDirectory. Don’t forget to make setId() private to meet the design!
Student hashCode() and equals()
Generate hashCode() and equals() on all of the Student fields.
Student toString()
Override toString() by right clicking in the editor (inside the Student class definition) and selecting Source > Override/Implement Methods. Select toString().
toString() should return a string containing the fields as a comma separated line as defined in [Student Records Data Format] and [Use Case 4: Save Student Directory]. Note that you are not yet implementing the save functionality, just the output format of a single student record.
The teaching staff tests are utilizing hashed passwords when creating Student objects. If your toString() method is implemented incorrectly, then there may be a problem reading the test output on Jenkins limiting your feedback. Test your Student.toString() method with the provided StudentTest class.
Javadoc your Code
Make sure that you Javadoc the Student class, state, and methods. For the overridden methods equals(), hashCode(), and toString(), remove the green comments and Javadoc them to describe how the methods work in Student. Do NOT delete the @Override annotation.
Run CheckStyle to ensure that your Javadoc has all elements.
Reference: Staging and Pushing to GitHub
GitHub Resources:
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: Interpreting Jenkins
Check the following items on Jenkins for your last build and use the results to estimate your grade:
Check Jenkins
At this point your project should build on Jenkins with a Yellow ball. That is because there are failing tests in StudentRecordIO that we haven’t gotten to yet. When fixing test failures, focus on failures in TS_StudentTest. Make sure that all TS_StudentTest methods are passing before moving on to StudentRecordIO.