• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about treemaps

 
Lynn Finley
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created an array of objects and placed them in a treemap. from the treemap, i have to print the items in the collection from a method and without a method.
I have to get user input to get and remove an employee from collection. (I have to use id as key) But this code is not working, if someone can look at it and point me in the right direction, i would appreciate it.

If anyone can please.....look at this and help i will be forever grateful..
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

for(int i=0; i<accts.length; i++)//add objects to treemapaccount.put("ID",accts);

in this statement you put "ID",accts. its not valid. you should use,
treemapaccount.put(((Employee)accts[i]).getID(),accts[i])
try it and let me know if it works..
regards
maulin.
 
Lynn Finley
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Maulin,
Thank you
When I put that in it allowed me to print my array, however it's printing them twice.
I tried commeting out each of my methods to see if I could get any of them to work it said "Statement Expected"...do you know what this message means??
EmployeeMap.java :55: Statement expected.
public void getName(map m)
^
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the compiler is telling you that it expected a statement, then it expected a statement where it found something else. Perhaps you've a problem with brackets. According to Roedy Green's List of Java Error Messages, you may be missing missing a } in a method.
 
Lynn Finley
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have checked and double checked all of my brackets. Am i passing the right paramater to my methods? I think I should pass my collection, in order to iterate over to get the user input? Am I anywhere on the right track.
 
Lynn Finley
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is my updated code.
It seems as usual once something is fixed you get 10 more errors. I don't think I understand implementing treemaps much.
I'm getting error messages like
When I try to pass my map collection to the method it tells me incorrect type-- When I try to cast it as an Object it tell's me explicit cast needed to convert?
Also things like getValue() not a method of class java.lang.Object--I thought I was passing the treemap?
can anyone please give me some input.
 
Lynn Finley
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its me again.
I finally got the code to work, but because it is so long I was wandering if their was a way that i could pause my out put in between method calls.
Thanks in advance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic