Java Vector Problem

Status
You're currently viewing only TheOne's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

TheOne

Seniorius Lurkius
25
Hi guys,
I normally wouldn't bother you with such a simple problem but this is driving me up the wall.
I have to write a class called 'PeoplesAge'. The class contains the following methods: 'setNameandAge' and 'getAge'.
The getAge method has to find the ages of people between 20 and 30 and display the name and age (so the data has to be linked somehow if you see what I mean).
I will use the class from within an Applet and I cannot create new classes or methods (Sucks).
Ideally I want to use Vectors (the method of storage has to be dynamic). I am having problems linking the two vectors together (Name and Age vectors) so I can extract data from them.
The main problems arise because everything has to be done in these two classes and methods.

Can anyone suggest the best way to go about this? Would hashtables be the way forward? I'm not looking for someone to write the code for me, just point me in the general direction. Maybe some pseudo code ;o)

Many, many thanks for any help. I wouldn't ask if I weren't desperate.
TheOne
 

TheOne

Seniorius Lurkius
25
I have alreay created two instances of the vector.

AppletTester.class
-Created two vector instances of setNameandAge

setNameandAge.class
-need to find age between 20 & 30
eg.

Code:
while(int i=0; i<vector1.size; i++){
    if(vector1.elementAt(i)>20){
         buffer.ammend(vector1.elementAt(i);
     }
}
return buffer.stringTo();

I can't access the vector2 vector to add the corresponding name to a string buffer.

Pulling my heair out now. If only I could create other methods etc..
Argh!
 

TheOne

Seniorius Lurkius
25
Originally posted by R2P2:
Why can't you access the other Vector? :confused: It's in the same class, and both Vectors should be the same size and in the same order, so vector2.elementAt(i) should be the name of person who's age is vector1.elementAt(i).

Maybe I'm getting confused here but I created the two instances of the setNameandAge Vector in the AppletTester class. I thought these vectors would only be available from within AppletTester, not setNameandAge class. Bear in mind that all the calculation has to be done from within setNameandAge.

Thanks for all help so far.
Theone
 
Status
You're currently viewing only TheOne's posts. Click here to go back to viewing the entire thread.
Not open for further replies.