#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    29
    Rep Power
    0

    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.

    Code:
    class University
    	@@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
    
    	class Students
    		
    		# array of students
    		# method to add new students (which associates students with course)
    	
    		
    	
    	class Courses
    	
    		# method to modify course registrations
    	
    	class Profs
    	
    		# method to modify teaching assignments
    		
    end
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    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:
    Code:
    class University
       
       list_of_classes
       list_of_professors
       list_of_students
       # ... other lists
    
    end
    
    class Class
       list_of_prerequisites
       gpa_to pass
       taught_by  # <- a Professor Object
       list_of_students  # <- Student Objects
       # ...
    end
    
    class Professor
       # ...
    end
    
    class Student
       # ...
    end
    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.
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    29
    Rep Power
    0
    Originally Posted by L7Sqr
    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:
    Code:
    class University
       
       list_of_classes
       list_of_professors
       list_of_students
       # ... other lists
    
    end
    
    class Class
       list_of_prerequisites
       gpa_to pass
       taught_by  # <- a Professor Object
       list_of_students  # <- Student Objects
       # ...
    end
    
    class Professor
       # ...
    end
    
    class Student
       # ...
    end
    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.

    Thanks, I just got a copy...

IMN logo majestic logo threadwatch logo seochat tools logo