Results 1 to 14 of 14
  1. #1
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Unhappy How do I Link data of two maps toghther?

    Hi

    Need some help. Basically I'm working on program that will record lecturers and courses, and be able to add and remove and display both. I've created two Map collections for both, individual ones. Lecturer has a name and id, course has a title and code etc. But I want to assign a course with a lecturer, how abouts do I go to doing that?

    Any help would be appreciated as I'm really lost on this and its holding me back.

    Thank You

  2. #2
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    I'm not sure if I understand your question correctly, but I think you just want to link one map to another. I think you want something like
    Java Code:
    Map< Map<Name, ID>, Map<Title, Code> > masterMap;

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Agrees with Mr. Legumes. Please clearly state your high-level goal, not the steps you are trying to take to solve this. Your overall path may be wrong.

  4. #4
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    Ok what i'm trying to do is create a list of lecturers and a list of modules. Both have there own attributes like name, title, id etc.

    So for example lecturer has attributes name and id, now i've had to create a map so that i can link those two attributes, i can add, remove and display a course or lecturer fine in a map.

    But what I cant do is assign a course from the course map to a lecturer who is in there own map.

    What I want is that when I type in the id of a lecturer there value comes up and then give an option of assigning that lecturer with a course that is already in the list.

    Does that make sense? :blush:

    So basically i want to be able to link data from two maps with eachother.

  5. #5
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    You could create a third map that contained course and lecture values.

    Also remember you can get a Set of the keys in the map class by using
    Java Code:
    map.entrySet();
    However, I'm still having trouble understanding your question.

    Is English your native language?

  6. #6
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    Maybe i'm just reading the task wrong?

    This is what I have to produce:

    Produce a software that keeps track of courses teached by lecturers at College. For each course, a course code and title needs to be recorded, as well as this 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.
    (subjects changed)

  7. #7
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Mr.Beans View Post
    You could create a third map that contained course and lecture values.

    Also remember you can get a Set of the keys in the map class by using
    Java Code:
    map.entrySet();
    However, I'm still having trouble understanding your question.

    Is English your native language?
    Yes lol born and bred in the UK, I think perhaps cos i'm confused myself that i'm not explaining it properly. :o

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Ok what i'm trying to do is create a list of lecturers and a list of modules. Both have there own attributes like name, title, id etc.
    So for example lecturer has attributes name and id, now i've had to create a map so that i can link those two attributes, i can add, remove and display a course or lecturer fine in a map.
    So, correct me if I'm wrong, but I gather that you've got a Lectuer class that has at least a name field and and an id field, and have placed Lecturer objects into a Map to map each id (I'm guessing) with its corresponding Lecturer object, correct?

    But what I cant do is assign a course from the course map to a lecturer who is in there own map.
    What would you use as a key here? The course number? But could there be multiple instances of the same course (for instance CS101 can be taken on Mon and Wed, or the same course with a different lecturer can be taken Tues and Thrus)? Are you sure a Map is the best construct for what you want to do here?

    What I want is that when I type in the id of a lecturer there value comes up and then give an option of assigning that lecturer with a course that is already in the list.
    Then you'd be using a separate Map or other collection that combines the two selected objects. No problem there.

    So basically i want to be able to link data from two maps with eachother.
    No, you want to associate objects that are in one map with objects in another map. You're still just associating objects with objects, not maps with maps.

  9. #9
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    So, correct me if I'm wrong, but I gather that you've got a Lectuer class that has at least a name field and and an id field, and have placed Lecturer objects into a Map to map each id (I'm guessing) with its corresponding Lecturer object, correct?


    What would you use as a key here? The course number? But could there be multiple instances of the same course (for instance CS101 can be taken on Mon and Wed, or the same course with a different lecturer can be taken Tues and Thrus)? Are you sure a Map is the best construct for what you want to do here?


    Then you'd be using a separate Map or other collection that combines the two selected objects. No problem there.


    No, you want to associate objects that are in one map with objects in another map. You're still just associating objects with objects, not maps with maps.
    Yes I think you got it.

    So far I have created two classes for Lecturer and Course, which have there attributes in. Then I have created two classes which have the Map for the two, and I have a tester class to test the functions out.

    I've had to create a Map because I have to make the attributes of Lecturer and Course into one object, ie name and id into one object. So now that I have done that I want to as you said associate the objects with each other, so for example:

    John Smith 0100 - Networks N100

    ^ Lecturer ^ Course


    So how do I actually do that? Do I have to create another Map?

  10. #10
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    btw there are no days, basically a lecturer could teach many courses, and a course could have many lecturers.

  11. #11
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Produce a software that keeps track of courses teached by lecturers at College. For each course, a course code and title needs to be recorded, as well as this 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.
    I would make a class that extends AbstractList. You don't need a Map for this.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  12. #12
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    I havent done abstarctlist so not sure what that is, and if I'm honest I don't want to start all over, I already have 10 variations of application, and the one i'm working on now is the only one that actually works the best bar the issues I have raised here, unless I cant find a solution then I'll probably need to start from scratch again.

    I've discovered something called MultiMap, that could possibly be the solution?

  13. #13
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Could you not just create a course class which contains a map of lectures and their id's, then have a map of courses and their ids.

    Java Code:
            Map<String, Course> courseMap;
            courseMap.get("n1000").getLecture("0100");

  14. #14
    javanoobie is offline Member
    Join Date
    Mar 2009
    Posts
    18
    Rep Power
    0

    Default

    ^ well i'm not really sure what you mean there I already have two seperate classes for holding the list of lecturers and courses in a map. But what I dont know how to do is assign a course to a lecturer. Basically I need a method that will allocate a course to a lecturer.

    For example when adding a new lecturer into the map this is the method for it:

    Java Code:
    public boolean addLecturer(Lecturer lecturerIn)
        {
          String keyIn = lecturerIn.getID(); // lecturer ID will be key of map
          if (lecturers.containsKey(keyIn)) // check if id is already in use
          {
            return false; // indicate error
          }
          else // ok to add the new lecturer
          {
            lecturers.put(keyIn, lecturerIn); // add key and lecturer pair into map
            return true;
          }
        }
    ^ What the above code does is it adds a NEW lecturer into the map, it assigns the key as the lecturer ID, and the value as the lecturers name. So say if I wanted to display this lecturer all I have do is call the key and it will show its value.

    Now what I need is a method where it can get a lecturer that has already been added into the map and then allocate it with a course that also has been added into the list. ie not any new data.

    But the problem is I dont know how to and its doing my head in cos ive been stuck on this for the last four days now. So if anyone knows the code for this method please let me know.

    :(

Similar Threads

  1. jsf command link
    By Srikala in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 06-29-2010, 03:38 PM
  2. Caching dynamic-maps in Hibernate
    By leonus in forum JDBC
    Replies: 0
    Last Post: 06-02-2008, 02:06 PM
  3. Link for 64 bit JDK.
    By aparna in forum New To Java
    Replies: 0
    Last Post: 03-19-2008, 03:15 PM
  4. Google Maps API
    By mew in forum New To Java
    Replies: 0
    Last Post: 12-26-2007, 11:28 AM
  5. Link List
    By one198 in forum New To Java
    Replies: 0
    Last Post: 10-14-2007, 02:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •