views:

323

answers:

9

This the description of the program brief:

Produce a software that keeps track of courses taught by lecturers at College. For each course, a course code and title needs to be recorded, as well as a list of lecturers taking that course needs to be recorded. The system should allow courses and lecturers to be added and removed from the list and information such as lecturers taking a course and courses registered to a particular lecturer to be displayed.

--

So far I have two classes Lecturer and Course and they two attributes such as name id, and code and title respectively. I have then created two more classes to hold the data for both of those objects and I have used a Map, so I have mapped id and name for Lecturer and code and title for course, they are both in seperate classes called LecturerList and CourseList.

But now I can't allocate a course to a lecturer. have been stuck on this for a week now. Any ideas? Have I approached this the wrong way?

I badly need help.

Thank you

A: 

The problem description is screaming "Database!". This problem is about tracking related sets of information, the very thing database software was designed for. My solution to this problem would be to use mySQL, and the Java database connector for mysql.

it is probably for an OOP programming or modelling course where a database is beyond the scope (or intention) of the assignment
TofuBeer
@TofuBeer You would be surprised at how often they start to build the roof before the basement...
Varkhan
+2  A: 

How about using a map, like:

   Map<Course, Lecturer>

or

   Map<Lecturer, List<Course>>
TofuBeer
+1  A: 

Try following one of the approaches described in this thread:

Process to pass from problem to code

It describes general approaches though.

I hope it helps

John
A: 

Try to make a functional schema (I almost wrote UML) of what you are trying to achieve. Ideally, use a piece of paper, a pencil, and draw boxes for each functional entity (Lecturer, Course, etc), and draw a labeled, oriented line for each type of relationship between these entities. Use colors, if need be.

If you think of the lines you have drawn as pieces of rope, on what such relationships do you need to "pull" to get the lists you are asked for?

Then and only then, try to design the class structure...

Varkhan
Don't think UML. Think Conceptual Data Model. That's really what he needs.
+1  A: 

I disagree that the problem needs a database. It's the object-oriented part that you're having problems with. Get that right and a database will follow if you need persistence.

I'd start with Course and Lecturer, as you did. Course would have the required code and title attributes, plus a List of Lecturers teaching it. Likewise, Lecturer would have a name attribute and a List of Courses being taught. It sounds like a bi-directional 1:m relationship to me. The language of your problem statement is a bit confusing, but it sounds like a Course can be taught by several Lecturers (perhaps because there are several sections of a given Course), and a Lecturer can teach more than one Course.

If this sounds accurate, I don't think you need a CourseList or LecturerList class.

duffymo
A: 

I would suggest storing a list of courses within the Lecturer and a list of Lecturers in the Course. Then create a service that models the "system", something like:

  Course {
    String code;
    String title;  
    List<Lecturer> lecturers = new ArrayList<Lecturer>();
    ... accessors & other business rules ...
    }

  Lecturer {
      int id;
      String name;
      List<Course> courses = new ArrayList<Course>();
    ... accessors & other business rules ...
    }

LectureServices {
 List<Course> coursesAvailable = new ArrayList<Course>(); 
 addCouse(Course course) {
  coursesAvailable.add(course);
 }
 addLecturerToCourse(Lecturer l, Course c) {
  ... lookup course ...
  c.addLecturer(l);
  l.addCourse(c);
 }

 ... etc ...
}
Rich Kroll
A: 

Hello guys, thank you very much for your replies, but I am still confused as to how to go about doing this, i've coded half the program, things like adding students, adding modules, and displaying each respectively. But i'm really stuck on the bit where i need a function that assigns a module to a student.

The way I have done this so far is I have used maps to map the attributes of Student(id and name) and Module(code and title), but i cant for the life in me figure out how to assign a module to a student, ive been stuck on this for a week. The modules and students are stored in maps of there own, but i just need a method where i can call a module from the module map and assign it to a student in the student map, any ideas?

Edit: sorry its meant to be lecturer and course and not student and module

A: 

Start with your basic objects and what properties they have

student -> id, name, list of courses

lecturer -> name, list of courses

course -> code, name, list of students, list of lecturers

From your requirements, the course appears to be the major component of interest, so let that be the place to start.

Since a student takes a course (not the other way around), the key function should be an operation on the course [course.addstudent]. But, you also need to be able to list all the courses a specific student is taking, so you need to keep a list by student somewhere, and the student object makes sense [student.addCourse]. Since adding the student to a course and creating the list of courses a student is taking, is a single logical "action", it makes sense to have a single function that handles the entire thing- and I would go back to the course, since it's what your really maintaining, as the place to do that.

The psuedocode isn't be perfect, but you can get the idea:

course.addStudent(student) {
   course.listOfStudents.add(student)
   student.addCourse(this)
}

student.addCourse(course) { student.listOfCourses.add(course) }

Deleting a student from a course, and adding and deleting the lecturer is similar.

David
A: 

You've used maps to map lecturer and course IDs to attributes? That doesn't sound very object-oriented, and in Java you'll have trouble if you try to not be OO!

This sounds to me like the sort of application where you will want to maintain bidirectional links between Lecturer and Course: i.e. each course has one lecturer --- is that always true? --- so Course has get/setLecturer methods, and each Lecturer has a container of Courses with add/set/remove/getCourse(s) methods. You shouldn't need to maintain external tables to store the Lecturer & Course details, or their mappings: in Java the objects themselves can be stored directly as everything is really a reference.

If this is to be used in anything approaching a production environment then you will want a database and I can recommend the Hibernate object-relational mapping system (especially using annotation-driven persistence) for automating much of the database retrieval, storage, cascading deletion, query pooling strategies, etc. But if this is just a pedagogical exercise, then that will be far too heavy. Oh, and if you're using this in production, maybe having a look at some existing course management / virtual learning environment software: see the bottom of http://en.wikipedia.org/wiki/Virtual_learning_environment for some references.

andybuckley