I’ve got a Dictionary<int BossID, string BossName> ListOfBosses and Dictionary<String EmpName, int BossID> ListOfEmps . Of course, Match the BossID to the Boss and return ‘Dictionary WhoIsMyBoss’.
I have no idea where to start in Java.
As far as the two lists go, we’ll assume there is going be a one to many ratio of Bosses to Emps. And the BossIDs are incremental from 1-n.
I figure I would do the following in my illiterate Java. . .
Dictionary<BossName, EmpName> WhoIsMyBoss;
ArrayList<Integer> AnotherListOfBosses;
private int Boss;
for (String EmpName: ListOfEmps)
Boss = ListOfEmps.get(EmpName)
WhoIsMyBoss.put(ListofBosses(Boss) , EmpName);
AnotherListOfBosses.add(Boss);
}
for(int Boss: AnotherListOfBosses)
{
ListOfBosses.remove(Boss)
}
That should leave me a list of Bosses and Employees and a
a ListOfBosses with no corresponding Employees hopefully.
How does that look? Is Dictionary the correct Collection to use? Any improvements would be greatly appreciated.
As Kilian Foth mentioned, you should use Map instead of
Dictionary. Additionally in Java the convention is to start variable names with a lowercase and classname uppercase letter.You said that the names are strings and the IDs integers.