A vector/arraylist deals w. objects. You must define
a Student class that takes the lines of initial values
in its constructor like:
read name,
read points,
read notes,
create Student object w. the three values,
store in vector (v.addElement(aStudent))
read name,
read points,
read notes,
create .... etc.
The you retrieve it like
Student aStudent=(Student)v.elementAt(i).
For simplicity you could implement the equals method in
you Student class to enable lookup in the Vector like
Code:
public void boolean equals (Object ob) {
if (!(ob instanceof Student) return false;
Student someStudent=(Student)ob;
return this.name.equals(someStudent.name);
}
With this in place you can do like:
if (v.contains(someStudent)) ....
or
int ix=v.indexOf(someStudent);
Without the implemented equals method the contains and indexOf methods just compares pointer (address) values, and that is ok just for rare occations...
Bookmarks