public class Faculty {
static int arrcounter=0;
int counter=0;
int studentNum=0;
StudentImpl students[];
Faculty(int num){
studentNum=num;
students=new StudentImpl[studentNum];
}
Faculty(StudentImpl []studentsarr){
this.students=studentsarr;
studentNum=studentsarr.length;
}
class TravelerImpl implements Traveler{
TravelerImpl()
{
}
public Object Current(){
return students[counter];
}
public boolean end(){
if (counter==studentNum)
return true;
else
return false;
}
public void next(){
if(counter<20)
{
counter+=1;
}
}
}
public Traveler GetTraveler(){
TravelerImpl t=new TravelerImpl();
return t;
}
How to use in main:
Traveler trav=ort.GetTraveler();//get the actual iterator object
while(!trav.end()/*to check if we're at the end*/){
( (Student)trav.Current()/*The current thing the iterator is pointing at*/).PrintNormal() ;
trav.next();//Get the next thing
}