Class Student -- representing a student and her or his schedule
- Attributes
- Student's name and the list of courses the student is taking. The name should be a string. The elements of the course list should be of type Class.
- Specific constructor
- Student( String s )
- Configures the new student to have name s and a Course list with no elements
- Configures the new student to have name s and a Course list with no elements
- Student( String s )
- Standard methods
- String toString()
- Returns a string representation of the student
- Returns a string representation of the student
- boolean equals( Object v )
- Determines whether v both is a student and has the same name and courses as this student
- Object clone()
- Returns a new Student with the same name and Course list
- String toString()
- Inspectors
- String getName()
- Returns the name of the student
- Returns the name of the student
- int length()
- Returns the number of courses the student is taking
- Course getCourse(int i )
- If is a legal index, then it returns the ith Course being taken by the student. If i is not a legal index, then it returns null
- String getName()
- Mutator
- void addCourse( Course c )
If c is already one of the student's course then no action is taken, otherwise both c is added to the course list and the student is added to the c's roster
- void addCourse( Course c )
Class Course -- representing a college course with its name and roster
- Attributes
- Course name and student roster. The course name is a string the roster is a list of students. An element of the roster would be of type Student.
- Course name and student roster. The course name is a string the roster is a list of students. An element of the roster would be of type Student.
- Constructors and methods
- So what would be the corresponding behaviors for a Course? Please hand in at the START of class on Friday a TYPED description of class Course. With respect to detail your description should follow my outline of class Student. If you desire,your description can be given in a Java file Course.java. I am NOT asking you to implement Course (at least for now). I am asking you WHAT SHOULD BE THERE and HOW IT SHOULD OPERATE.
- So what would be the corresponding behaviors for a Course? Please hand in at the START of class on Friday a TYPED description of class Course. With respect to detail your description should follow my outline of class Student. If you desire,your description can be given in a Java file Course.java. I am NOT asking you to implement Course (at least for now). I am asking you WHAT SHOULD BE THERE and HOW IT SHOULD OPERATE.
- The Student and Course classes seem relatively simple but they have some interesting gotchas if you are not careful. We will discuss them on Friday and more on Monday. If things go slow, our exam will be moved back to Friday. Be dressed nice on Friday as I expect it to be class picture day.
Help for implementing a list
- Read about the standard Java class ArrayList -- section 8.10