97.0k views
4 votes
Student: extends Person

- numStudents: static int
- studentlD: int / generated
- coursesTaken: Course[] //initialize to length of 50
- numCoursestaken: int //controlled variable
- isGraduate: boolean
- major: String // "undeclared" default value
+ Student() 1// coursesTaken = D, numCourses Taken =0, is , adaduate = false
+ Student(boolean isGraduate)
+ Student(String major, boolean isGraduate)
+ Student(String name, int birthYear, String major, boolean isGraduate)
+ isGraduate() boolean
+ getNumCoursesTaken() int
+ static getNumStudents(): int
+ getStudentID(): int
+ getMajor(): String
+ setlsGraduate(boolean isGraduate) void
+ setMajor(String major) void
+ addCourseTaken(Course course): void //appends course to the end of the existing array
+ addCoursesTaken(Course [] course) void //appends courses to the end of the existing array
+ getCourseTaken(int index): Course // note: index must be verified. Return "null" if invalid
+ getCourseTakenAsString(int index): String // note: index must be verified. Return " if" invalid // returns "courseDept-courseNum"
+ getAllCoursesTakenAsString0): String // comma separated list of all courses taught // uses getCourseTakenAsString(int index) as a helper method
+ equals(Object obj): boolean //all attributes inherited +local must match for 2 Student objects to be considered equal
+ toString0: String // Student: studentiD: %04d ∣ Major %20 s ∣%14 s∣ Number of Courses Taken: %3d | Courses Taken: %s", studentiD, major, Graduate/Undergraduate, numCoursestaken, getAllCoursestakenAsString()
+ compareTo(Person p) int /luse the Comparable interface specification, sort by numCredits

User AdmiralWen
by
7.5k points

1 Answer

4 votes

Final answer:

The student class extends the Person class and includes attributes and methods related to students. It has constructors to initialize the object with different parameters, getter and setter methods for various attributes, and methods to add and retrieve courses taken. It also includes overridden equals and toString methods. The compareTo method implements the Comparable interface to compare students based on their credit count.

Step-by-step explanation:

  • extends Person: Extending Person class to inherit its attributes and methods.
  • numStudents: static int: A static variable to keep track of the number of student objects created.
  • studentID: int: An auto-generated ID for each student.
  • coursesTaken: Course[]: An array to store the courses taken by the student. Initialized to a length of 50.
  • numCoursesTaken: int: A controlled variable to keep track of the number of courses taken.
  • isGraduate: boolean: Indicates whether the student is a graduate or undergraduate.
  • major: String: Represents the major of the student with a default value of 'undeclared'.
  • Student(): Default constructor to initialize the student object with default attribute values.
  • Student(boolean isGraduate): Constructor that takes the isGraduate parameter to initialize the student object.
  • Student(String major, boolean isGraduate): Constructor that takes the major and isGraduate parameters to initialize the student object.
  • Student(String name, int birthYear, String major, boolean isGraduate): Constructor that takes the name, birthYear, major, and isGraduate parameters to initialize the student object.
  • isGraduate(): boolean: Getter method to retrieve the isGraduate value.
  • getNumCoursesTaken(): int: Getter method to retrieve the numCoursesTaken value.
  • static getNumStudents(): int: Getter method to retrieve the numStudents value.
  • getStudentID(): int: Getter method to retrieve the studentID value.
  • getMajor(): String: Getter method to retrieve the major value.
  • setIsGraduate(boolean isGraduate): Setter method to set the isGraduate value.
  • setMajor(String major): Setter method to set the major value.
  • addCourseTaken(Course course): void: Method to add a course to the coursesTaken array.
  • addCoursesTaken(Course[] courses): void: Method to add multiple courses to the coursesTaken array.
  • getCourseTaken(int index): Course: Method to retrieve the course at the specified index from the coursesTaken array.
  • getCourseTakenAsString(int index): String: Method to retrieve the course as a string at the specified index from the coursesTaken array.
  • getAllCoursesTakenAsString(): String: Method to retrieve a comma-separated list of all courses taken as strings. It uses the getCourseTakenAsString(int index) method as a helper method.
  • equals(Object obj): boolean: Overridden equals method to compare two Student objects based on their attributes.
  • toString(): String: Overridden toString method to convert the Student object to a string representation.
  • compareTo(Person p): int: Implemented Comparable interface method to compare two Person objects based on their numCredits attribute.
User Benjamin Ronneling
by
8.2k points