• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HashMap Issues and Such

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

This is for an assignment so any assistance in sending me in the right direction so I can learn this better would be appreciated.

The assignment is to use a HashMap to enter some simple employee data via an applet. I need to add a record, find a record, remove a record, and clear using a single actionEvent process so there are to be no inner classes.

I have made the applet and the code compiles if I take out the actionEvent call to the Employee class. I am far from being able to complete the assignment, and I am frustrated at the lack of information about HashMaps in the text (Head First Java) and how I can go about processing these various actions using the available buttons.

Yes I am a crappy programmer...no I don't ever want to develop Java professionally. I am otherwise an excellent non-traditional student who mistakenly took an advanced Java class to graduate this spring instead of VB.NET over the summer and I need a nudge here and there to get a half-way decent grade. Java just kicks my Big Picture butt even though I can read through code and understand what it does, creating a solution out of thin air eludes me.

Thanks for any pointers to code examples I can learn from.

Here is the admittedly weak code I have so far:




I really have been searching through the archives, other java sites, the API, and such to no avail. I would sincerely appreciate any assistance.

Thanks in advance.

BDH
[ March 29, 2005: Message edited by: Barry Huizenga ]
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S.

I get the error stating the non-static getNumber() method can not be called from a static context. I am not sure what the instance would look like when trying to get the user entered information out of the text field and put into the HashMap.

I don't even know if I am on the right track whether the information is to be retrieved via getText() from the Employee class or from the actionEvent add button listener.

I'm brewing coffee so I'll be here all night and tomorrow. If I fail, my wife is going to kick me out of the house and I'll have to live in a cardboard box beneath an overpass.

BDH
 
slicker
Posts: 1108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ~think~ you want to actually instantiate an Employee class in this block and then set the values of the variable.

current = new Employee( name from text field, number from text field, etc.)
now put current into the employees map.


if (source == addButton) {
employees.put(new Integer (Employee.getNumber(), Employee.getName()));//employees.put(new String (current.getName()));//employees.put(new Double(current.getRate()));recordCount.setText("The collection has " + employees.size() + " employees");}


p.s. It's late and I need to go home now!!
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can dig it. My brain is tired from looking at this all day.

Eh...I have been trying to instantise current to add it to Employee, but I just ain't seeing it.

Good thing I like the smell of cardboard

BDH
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You code is wrong at this point

employees.put(new Integer (Employee.getNumber(), Employee.getName()));

You can't access getNumber() an .getName() without actully instantiating an instance of the Employee object.

I have a solution as per my understanding.

if (source == addButton) {
//Get all values from the Applet UI Components like getText() or whatever.
//Create an employee object there itself local -emp
//set all fields
//Put this emp into the emps - member variable-Map

Regards
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks...yup it's wrong.

I have been working on a solution that is right along the lines suggested and will post it later when I've worked it out. I am sure there will be further problems.

BDH
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ack!

OK, I have entered this...




...but I am getting an error stating "cannot resolve symbol constructor Employee (java.lang.Integer, java.lang.String)" and cannot resolve symbol constructor Integer (int.Project3.Employee)"

I know getting the instances right is a major conceptual problem I have with Java and I am in therapy for it. Be that as it may, I need a good and simple link because the mechanics of it are not sinking in.

BDH
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


...but I am getting an error stating "cannot resolve symbol constructor Employee (java.lang.Integer, java.lang.String)" and cannot resolve symbol constructor Integer (int.Project3.Employee)"



1. For the cannot resolve constructor employee error, the employee constructor takes an int, not an Integer. You could try

int number = Integer.parseInt(empNumber.getText()); instead of
Integer number = new Integer(empNumber.getText());


2. Looks like you have a misplaced paren and it thinks you are trying to create an Integer from an int + an employee.

employees.put(new Integer(current.getNumber()), current);
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Carol!

The first part I figured out and the second you were right on and I just couldn't see it.

Now to get on the rest of it!

BDH
 
Barry Huizenga
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey since I have no confidentiality problem exposing my ignorance, how about helping me get over the next hump? I am buying beverages to any who help if you are ever in the Grand Rapids area

So here is the latest code:



The applet buttons don't work properly, but the Add button is the only one currently completed as I would expect it will look ultimately.

The aggravating thing is that the execute only updates the files on the first time. If I change and save the file and open the html file the second time, the changes are not incorporated.

I am using JCreator to type this up and since I know it and comfortable with it, I would prefer to keep it as my IDE.

So specific questions:

Why don't the buttons work?
What is going on at time of compilation?

Thanks for any push in the right direction.

BDH
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic