Untitled


SUBMITTED BY: Guest

DATE: Nov. 22, 2014, 3:26 p.m.

FORMAT: Java

SIZE: 1.1 kB

HITS: 688

  1. public class Faculty {
  2. static int arrcounter=0;
  3. int counter=0;
  4. int studentNum=0;
  5. StudentImpl students[];
  6. Faculty(int num){
  7. studentNum=num;
  8. students=new StudentImpl[studentNum];
  9. }
  10. Faculty(StudentImpl []studentsarr){
  11. this.students=studentsarr;
  12. studentNum=studentsarr.length;
  13. }
  14. class TravelerImpl implements Traveler{
  15. TravelerImpl()
  16. {
  17. }
  18. public Object Current(){
  19. return students[counter];
  20. }
  21. public boolean end(){
  22. if (counter==studentNum)
  23. return true;
  24. else
  25. return false;
  26. }
  27. public void next(){
  28. if(counter<20)
  29. {
  30. counter+=1;
  31. }
  32. }
  33. }
  34. public Traveler GetTraveler(){
  35. TravelerImpl t=new TravelerImpl();
  36. return t;
  37. }
  38. How to use in main:
  39. Traveler trav=ort.GetTraveler();//get the actual iterator object
  40. while(!trav.end()/*to check if we're at the end*/){
  41. ( (Student)trav.Current()/*The current thing the iterator is pointing at*/).PrintNormal() ;
  42. trav.next();//Get the next thing
  43. }

comments powered by Disqus