Java help please >.<

Discussion in 'General Computer Support' started by brushfire, Oct 8, 2009.

  1. brushfire

    brushfire

    Joined:
    Oct 8, 2009
    Messages:
    1
    Hey all,

    having some issues with a java project. The compiler is not liking my iterator, any help?

    Code:
    package LLStuff;
    
    import java.io.Serializable;
    import java.util.Comparator;
    import java.util.Iterator;
    import java.lang.Iterable;
    
    public class LinkedList<E> implements ListInterface<E>, Iterable<E>{
      ..
      private Iterator<E> iter;
    <snip>
    /* using private inner class for my iterator, prof's specs*/
    
    	@Override
    	public Iterator<E> iterator(){
    		iter = new ListIterator(this);
    		return iter;
    	}
    	
    	class ListIterator implements Iterator<E>{
    		Link<E> cur;
    		private int modcount;
    		private LinkedList<E> a;
    		int tracker = 1;
    		
    		public ListIterator(LinkedList<E> e){
    			a = e;                                                                        
    			modcount = a.mod;
    			cur = a.headlink;
    		}
    		
    		@Override
    		public boolean hasNext() {
    			return(cur.next != null);
    		}
    
    		@Override
    		public E next() {
    			if(a.mod != modcount) throw new RuntimeException("Unexpected list modification");
    			else{
    				cur = cur.next;
    				tracker++;
    			return (E)cur.data;
    			}
    		}
    
    		@Override
    		public void remove() {
    			a.remove(tracker);
    			tracker--;
    			modcount++;
    		}
    	}
    
    /* as far as I can tell, the methods were implemented correctly,
    now, onto the problem code*/
    
    import LLStuff.LinkedList;
    import LLStuff.ListInterface;
    public class StudentLists{
      public static void main(String[] args){
        ListInterface<Student> masterList = new LinkedList<Student>(compName);
    <snip>
    for(Student x: masterList){
    /* this line gives me a compiler error stating that only arrays or instances of java.lang.Iterable can be used with 
    an enhaced for loop. As far as I can tell, the methods were all implemented according to the specs, everything
    was imported, and everything is referenced correctly. Why does the compiler not read that masterList (of type
    linkedList implements iterable? */
    brushfire, Oct 8, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Kohan

    JAVA VIRTUAL MUCHINE OR SUN JAVA

    Fernando Kohan, Nov 13, 2004, in forum: Firefox
    Replies:
    1
    Views:
    821
    Clark
    Nov 14, 2004
  2. tpg comcntr

    HELP! HELP! PLEASE, PLEASE, PLEASE

    tpg comcntr, Feb 14, 2004, in forum: Computer Support
    Replies:
    11
    Views:
    868
    michael turner
    Feb 15, 2004
  3. dakine

    MS Java or Sun Java???

    dakine, Jul 20, 2004, in forum: Computer Support
    Replies:
    9
    Views:
    1,456
  4. emerald
    Replies:
    3
    Views:
    12,754
    The Modfather
    May 14, 2006
  5. chuck

    Firefox and Java - but no Java

    chuck, Mar 19, 2007, in forum: Firefox
    Replies:
    1
    Views:
    359
    Peter.Potamus.the.Purple.Hippo@gmail.com
    Mar 19, 2007
Loading...

Share This Page