Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: NEED SERIOUS HELP CODING THIS PROGRAMMING ASAP

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy NEED SERIOUS HELP CODING THIS PROGRAMMING ASAP

    import java.util.Iterator;
    import java.util.NoSuchElementException;
     
    public class List<E> {
     
      private E[] listArray = (E[]) new Object[300];
      private int size = 0;
        private int currentPosition=0;
     
     
      /**
       * Inserts the specified element at the beginning of this list.
       *
       * @param element element to be appended to this list
       */
      public void addFirst(E element) {
        for (int i=size; i>0; i--) {
          listArray[size] = listArray[size-1];
        }
        listArray[0] = element;
        size++;
      }
     
      /**
       * Appends the specified element to the end of this list.
       *
       * @param element element to be appended to this list
       */
      public void addLast(E element) {
        for (int j=size; j>0; j++) {
            listArray[size] =listArray[size-1];
                }
        listArray[size] = element;
        size++;
      }
     
      /**
       * Removes all of the elements from this list.  The list will be
       * empty after this call returns.
       */
      public void clear() {
        for(int x=0; x<size;x++) {
            listArray[x]=null;
        }
        size=0;
      }
     
      /**
       * Returns <code>true</code> if this list contains the specified
       * element. More formally, returns <code>true</code> if and only
       * if this list contains at least one element <code>e</code> such
       * that (<code>o==null ? e--null : o.equals(e)</code>).
       *
       * @param o element whose presence in this list is to be tested
       * @return <code>true</code> if this list contains the specified element
          */
      public boolean contains(Object o) {
         throw new java.lang.RuntimeException("Method not implemented");
        }
     
     
     
     
      /**
       * Returns the first element from this list.
       *
       * @return the first element from this list
       * @throws NoSuchElementException if this list is empty
       */
      public E getFirst() {
        return listArray[0];
      }
     
      /**
       * Returns the last element from this list.
       *
       * @return the last element from this list
       * @throws NoSuchElementException if this list is empty
       */
      public E getLast() {
        return listArray[size-1];
      }
     
      /**
       * Returns the element at the specified position in this list.
       *
       * @param index index of the element to return
       * @return the element at the specified position in this list
       * @throws IndexOutOfBoundsException if the index is out of range (
       * <code>index < 0 || index >= size()</code>)
       */
      public E get(int index) {
    for(index=0;index >=size;index++)
    return listArray[index];
        throw new java.lang.RuntimeException("Method not implemented");
     
      }
     
      /**
       * Returns the index of the first occurrence of the specified element in
       * this list, or -1 if this list does not contain the element.
       *
       * @param o element to search for
       * @return the index of the first occurrence of the specified element in
       * this list, or -1 if this list does not contain the element
       */
      public int indexOf(Object o) {
        throw new java.lang.RuntimeException("Method not implemented");
      }
     
      /**
       * Returns <code>true</code> if this list contains no elements.
       *
       * @return <code>true</code> if this list contains no elements.
       */
      public boolean isEmpty() {
        return size == 0;
      }
     
      /**
       * Removes and returns the first element from this list.
       *
       * @return the first element from this list
       * @throws NoSuchElementException if this list is empty
       */
      public E removeFirst() throws NoSuchElementException {
        throw new java.lang.RuntimeException("Method not implemented");
      }
     
      /**
       * Removes and returns the last element from this list.
       *
       * @return the last element from this list
       * @throws NoSuchElementException if this list is empty
       */
      public E removeLast() {
        throw new java.lang.RuntimeException("Method not implemented");
      }
     
      /**
       * Returns the number of elements in this list.
       *
       * @return the number of elements in this list
       */
      public int size() {
          throw new java.lang.RuntimeException("Method not implemented");
     
      }
     
      /**
       * Returns an iterator over the elements in this list in proper sequence.
       *
       * @return an iterator over the elements in this list in proper sequence.
       */
      public Iterator<E> iterator() {
          public boolean hasNext() {
     
              if (size > currentPosition)
                  return true;
     
              else
                  return false;
          }
          public Object next() {
              return listArray[currentPosition];
          }
          public void remove(){
    throw new java.lang.RuntimeException("Method not implemented");
     
        }
    }
    Last edited by copeg; September 20th, 2010 at 02:12 PM. Reason: Code tags


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: NEED SERIOUS HELP CODING THIS PROGRAMMING ASAP

    What exactly is the problem/question?

  3. #3
    Junior Member
    Join Date
    Sep 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: NEED SERIOUS HELP CODING THIS PROGRAMMING ASAP

    i'm not sure how to code the iterator function my teacher never showed us and i'm not sure if i'm doing it right

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: NEED SERIOUS HELP CODING THIS PROGRAMMING ASAP

    You need to move the pointer (currentPosition) at some point, otherwise it will be an infinite iterator.

Similar Threads

  1. NEED HELP ASAP!!
    By JavaStudent_09 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 18th, 2010, 07:33 PM
  2. NEED HELP ASAP PLEASE!!!
    By mbm4ever in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 12th, 2010, 07:01 PM
  3. Help me in java coding
    By smallmac in forum Java Theory & Questions
    Replies: 5
    Last Post: August 2nd, 2010, 09:50 AM
  4. Java coding help
    By Javalover1 in forum The Cafe
    Replies: 0
    Last Post: April 12th, 2010, 08:11 PM
  5. Sudoku coding help...please
    By sketch_flygirl in forum Algorithms & Recursion
    Replies: 2
    Last Post: December 5th, 2009, 10:07 PM