Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Student
- {
- // instance variables - replace the example below with your own
- private String forename;
- private String surname;
- private int id;
- private String address;
- //create numberOfCredits as an integer as of now
- private int studentCredits;
- //Create list of module student is enrolled on
- ObjectArrayList studentModules = new ObjectArrayList();
- public Student(String forename, String surname, int id, String address)
- {
- this.forename = forename;
- this.surename = surname;
- this.id = id;
- this.address = address;
- }
- //Taking mod as module name
- public boolean addEnrolledOn(Module mod)
- {
- //check if the module already exist in studentModules
- if (this.studentModules.contains(mod)) {
- return false;
- }
- else if (this.studentCredits + Module.numberOfCredits() <= 120) {
- //Add mod to studentModules
- //add the module's number of credits to studentCredits
- this.studentModules.add(mod);
- this.studentCredits += mod.numberOfCredits();
- return true;
- }
- else {
- return false;
- }
- }
- public boolean removeEnrolledOn(Module mod)
- {
- //If student has not recorded it is enrolled on module, return false
- // otherwise if successfully remove module, return true
- if (!Module.students.contains(student)) {
- return false;
- }
- else if (this.studentModules.remove(mod)) {
- this.studentCredits -= mod.numberOfCredits();
- return true;
- }
- }
- //Return amount of credits currently enrolled as in Integer
- public int creditsEnrolledOn()
- {
- return this.studentCredits;
- }
- //Check if object comparing is the same object, else return false
- public boolean equals(Object obj)
- {
- if (obj instanceof Student) {
- Student other = (Student) obj;
- if (other.forename.equals(this.forename) &&
- other.surname.equals(this.surname) &&
- other.id.equals(this.id) &&
- other.address.equals(this.address)) {
- return true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement