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 2 of 2

Thread: Is this correct? Tips if any please

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Is this correct? Tips if any please

    Hello all, new to the forum and trying my best to finish an assignment for my intermediate java class and was hoping someone could tell me if what I am doing in my assignment is right or wrong. If it's wrong any suggestions would be much appreciated! It's an abstract class which is used for an ArrayList and LinkedList, and my question of correctness involves addFirst and extractFirst methods


    public abstract class List<E> implements Iterable<E> {
     
     
    public abstract void insertElementAt(E element, int index);
     
     
    public abstract E removeElementAt(int index);
     
    //	/**
    //	 * Returns a String representation of this List.
    //	 * @return a String representation of this List.
    //	 */
     
    //	
    //	/**
    //	 * Inserts the specified element at the beginning of this List.
    //	 * @param element the element to insert.
    //	 */
    	void addFirst(E element) {
    //		// TODO implement this method (Problem 1 (b))
     
    		int i = 0;
    		if(i == 0){
    		   List.this.insertElementAt(element,i);
    		}
    	}
     
    //	
    //	/**
    //	 * Retrieves and removes the first element of this List.
    //	 * @return the first element of this List.
    //	 */
     
    	E extractFirst() {
    		// TODO implement this method (Problem 1 (c))
     
    		int index = 0;
     
    		if(index==0)
    			return null;
     
    			E e = List.this.removeElementAt(index);
    		    index = index+1;
    		return e;
     
    	}
     
    }
    Last edited by helloworld922; October 8th, 2011 at 01:00 PM.


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

    Default Re: Is this correct? Tips if any please

    someone could tell me if what I am doing in my assignment is right or wrong
    You tell us. You've given us no requirements, asked no specific question, and given us next to nothing to go by. Does it compile? Are there exceptions? Does it work as intended?

Similar Threads

  1. I have got an assignment and I really need help or any tips..thanks
    By celz in forum What's Wrong With My Code?
    Replies: 14
    Last Post: August 9th, 2011, 03:50 PM
  2. Some java tips
    By meghadwivedi in forum Member Introductions
    Replies: 1
    Last Post: May 16th, 2011, 09:44 AM
  3. Need some tips...
    By nine05 in forum JDBC & Databases
    Replies: 1
    Last Post: March 20th, 2011, 11:37 AM
  4. Looking for tips
    By TimoElPrimo in forum Member Introductions
    Replies: 3
    Last Post: February 15th, 2011, 08:51 PM
  5. Is My answers correct??
    By Java.Coder() in forum What's Wrong With My Code?
    Replies: 6
    Last Post: December 28th, 2010, 06:22 AM

Tags for this Thread