July 27th, 2008, 10:56 AM
Help with program
I want to make a very simple program that creates a mini university:
The mini university has 3 courses: math, science, and english. Each course has at least 1 student and exactly 1 prof.
There are 10 students: student_1 ... student_10. Each student takes 1 to 3 of the courses.
There are 2 profs: dr_smith teaches math & science; dr_jones teaches english.
I'm thinking I should create a 'University' parent class, with the subclasses 'Courses', 'Students', and 'Profs'. I would like the program to be able to figure out implicit associations between the subclasses, while having to state as few as possible explicitly. E.g., have a method within 'Courses' to add students to a course should automatically associate those students with that course and the teacher, and vice-versa.
I'll get to work, and update as I make progress. Any help along the way appreciated.
@@students = [ 1..10 ] # all students
@@courses = [ :math, :sci, :eng ] # all courses
@profs = [ :smith, :jones ] # profs
# method to look up student, prof, or course, and return all associated data
# array of students
# method to add new students (which associates students with course)
# method to modify course registrations
# method to modify teaching assignments
July 27th, 2008, 03:11 PM
Generally, the Courses, Professors and Students wont be 'subclasses' of University. You may want to design a situation where they will be part of a container class within University. For instance:
This is a perfect opportunity for you to look into design patterns. The defacto book on the subject - Design Patterns - is a great reference littered with real-world examples. I suggest you get a copy and see how you might try out some of the patterns yourself in this design.
# ... other lists
taught_by # <- a Professor Object
list_of_students # <- Student Objects
True happiness is not getting what you want, it's wanting what you've already got.
July 28th, 2008, 07:44 AM
Originally Posted by L7Sqr
Thanks, I just got a copy...