wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes HashMap Issues and Such Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap Issues and Such " Watch "HashMap Issues and Such " New topic
Author

HashMap Issues and Such

Barry Huizenga
Greenhorn

Joined: Jan 11, 2005
Posts: 8
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 ]

Meh
Barry Huizenga
Greenhorn

Joined: Jan 11, 2005
Posts: 8
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
John Dunn
slicker
Ranch Hand

Joined: Jan 30, 2003
Posts: 1108
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!!


"No one appreciates the very special genius of your conversation as the dog does."
Barry Huizenga
Greenhorn

Joined: Jan 11, 2005
Posts: 8
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
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
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


Sarath Mohan
Barry Huizenga
Greenhorn

Joined: Jan 11, 2005
Posts: 8
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

Joined: Jan 11, 2005
Posts: 8
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
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364

...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

Joined: Jan 11, 2005
Posts: 8
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

Joined: Jan 11, 2005
Posts: 8
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
 
wood burning stoves
 
subject: HashMap Issues and Such
 
Similar Threads
method not abstract
. . .not abstract and doesnt overide abstract method actionPerfomed
Multiple controls in a panel
Adding Exception error problems
grid bag panels overlap : please HELP if you can