Results 1 to 14 of 14
- 04-10-2009, 11:15 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
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
- 04-11-2009, 12:16 AM #2
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;
-
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.
- 04-11-2009, 12:33 AM #4
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
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.
- 04-11-2009, 12:42 AM #5
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
However, I'm still having trouble understanding your question.Java Code:map.entrySet();
Is English your native language?
- 04-11-2009, 12:46 AM #6
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
Maybe i'm just reading the task wrong?
This is what I have to produce:
(subjects changed)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.
- 04-11-2009, 12:48 AM #7
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
-
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?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.
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?But what I cant do is assign a course from the course map to a lecturer who is in there own map.
Then you'd be using a separate Map or other collection that combines the two selected objects. No problem there.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.
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.So basically i want to be able to link data from two maps with eachother.
- 04-11-2009, 01:03 AM #9
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
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?
- 04-11-2009, 01:39 AM #10
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
btw there are no days, basically a lecturer could teach many courses, and a course could have many lecturers.
- 04-11-2009, 04:05 AM #11
I would make a class that extends AbstractList. You don't need a Map for this.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.USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 04-12-2009, 06:33 PM #12
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
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?
- 04-13-2009, 04:54 AM #13
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");
- 04-13-2009, 05:37 PM #14
Member
- Join Date
- Mar 2009
- Posts
- 18
- Rep Power
- 0
^ 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:
^ 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.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; } }
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
-
jsf command link
By Srikala in forum JavaServer Faces (JSF)Replies: 2Last Post: 06-29-2010, 02:38 PM -
Caching dynamic-maps in Hibernate
By leonus in forum JDBCReplies: 0Last Post: 06-02-2008, 01:06 PM -
Link for 64 bit JDK.
By aparna in forum New To JavaReplies: 0Last Post: 03-19-2008, 02:15 PM -
Google Maps API
By mew in forum New To JavaReplies: 0Last Post: 12-26-2007, 10:28 AM -
Link List
By one198 in forum New To JavaReplies: 0Last Post: 10-14-2007, 01:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks