|
Post by EurasianVixen on Jan 31, 2002 21:25:34 GMT -5
Has anyone done the tutorial prep for this week yet regarding iterators? I really don't understand what u have to write in the constructor and the 2 methods ..
|
|
|
Post by Sky on Jan 31, 2002 22:38:09 GMT -5
the prep is quite similar to A2 part 2 but it's a lot easier... for the constructor...u only need one line u just have to set "list" that is inside the object equal to the incoming parameter "list" in the constructor (btw...i think there should be a "private" in front of Object [] list;)
for the hasNext()...obviously u return true when there is element in the list and false if there is none so u just have to set up another private int instance variable (i'll call it elementPos) that starts at 0 to read and later return the next element in the list...and inside the hasNext() method...u can just say...if the value of elementPos is less than the length of the list...=> there is still element in the list...so u can return true...if not...then return false
for the next() method...u just return the next object in the list ...for me...i just use another local String variable inside the method to store the current element that elementPos is pointing in the list...then i increment elementPos by 1 to make it points to the next element in the list(so it ready to return the next element) and then return the local String variable which contain the element that should be returned...
i think it's hard to say how to do it without posting any of my code... should i just post the solution then?
|
|
|
Post by EurasianVixen on Jan 31, 2002 23:11:35 GMT -5
oh, no thats fine. I think I get it. Thanks!
|
|