144k views
2 votes
Course

-isGraduate Course: boolean
-courseNum: int
-course Dept: String
-numCredits: int
+ Course(boolean isGraduate Course, int courseNum, String course Dept, int numCredits)
+ isGraduate Course(): boolean
+ getCourseNum(): int
+ getCourse Dept(): String
+ getNumCredits(): int
+ getCourseName: String //return String of "U" or "G" + course Dept + courseNum equals(Object obj): boolean llall attributes must match for 2 Course objects to be considered equal
+ toString(): String //"Course: %35-%3dNumber of Credits: %02d Graduate/Undergraduate", course Dept, courseNum, numCredits, isGraduateCourse
+ compare To(Course c): int //use the Comparable interface specification. Sort by courseNum

User Bo
by
8.3k points

1 Answer

4 votes

Final answer:

The question is about designing a Course class with attributes and methods to manage college course data. It provides a constructor, accessor methods, an equals method to check object equality, a toString method for text representation, and a compareTo method for sorting.

Step-by-step explanation:

The question relates to the implementation of a Course class in a programming context, likely within an object-oriented programming course. The attributes and methods indicate that the class models college courses, distinguishing between graduate and undergraduate courses, and includes comparison functionality.

A constructor is provided to initialize object instances and several accessor methods (like isGraduateCourse()) for retrieving course information. The equals() method determines if two Course objects are the same based on their attributes. The toString() method provides a standardized string representation of the course that includes its department, number, credits, and whether it is a graduate course. Lastly, the compareTo(Course c) method aims to impose a natural ordering on Course objects, primarily sorting them by the course number as per specifications of the Comparable interface.

User Hiro
by
8.3k points