I'm not seeing my bracket problem at all!

import java.util.*;

/** A class to represent an ordered list. The data is stored in a linked
*   list data field.
*   @author Koffman & Wolfgang
*/

public class OrderedList<E extends Comparable<E>>
        implements Iterable<E> {
    /** A linked list to contain the data. */
    private LinkedList<E> theList = new LinkedList<E>();

  public OrderedList() {
    theList = new LinkedList < E > ();
  }

  /** Insert obj into the list preserving the lists order.
      pre: The items in the list are ordered.
      post: obj has been inserted into the list
      such that the items are still in order.
      @param obj The item to be inserted
   */
  public void add(E obj) {
    ListIterator < E > iter = theList.listIterator();
    // Find the insertion position and insert.
    while (iter.hasNext()) {
      if (obj.compareTo(iter.next()) < 0) {
        // Iterator has stepped over the first element
        // that is greater than the element to be inserted.
        // Move the iterator back one.
        iter.previous();
        // Insert the element.
        iter.add(obj);
        // Exit the loop and return.
        return;
      }
    }
    // assert: All items were examined and no item is larger than
    // the element to be inserted.
    // Add the new item to the end of the list.
    iter.add(obj);
  }

  /** Returns the element at the specified position.
      @param index The index of the specified position
      @return The element at position index
   */
  E get(int index) {
    return theList.get(index);
  }

/**** EXERCISE ****/
	public ListIterator <E> iterator(){
		return myList.iterator();
	}
	public int size(){
		return myList.size();
	}
	public void remove(E obj){
		return myList.remove();
	}
  

	public OrderedList<E> getSubList(E obj1, E obj2){
                        OrderedList<E>subList = new OrderedList< E >();
		 //LinkedList<E> YourList = new LinkedList<E>();
		 if (obj.compareTo(myList.next() >= 0 && obj.compareTo(myList.next()) < 0));			
        iter.add(obj);			
				return;	
        }
 }
}

Here is the error message I'm getting

OrderedList.java:71: class, interface, or enum expected
}
^
1 error

Ignore line 72 its just a space.

Here is the error message I'm getting

OrderedList.java:71: class, interface, or enum expected
}
^
1 error

Ignore line 72 its just a space.

Just stuck your program in NetBeans. When you take out the bracket in line 72, the error message goes away, so it's not something to ignore and it's not just a space. It's what is giving you an error. Line 73 is a space and can be ignored, but the bracket on line 72 is what is giving you that error. Take it out. You'll still have errors, but you won't have that one unless there is more to the file that you didn't post.

I meant line 73 to ignore.

I know if I take out bracket on line 72 I get more errors. Or if I move it.

I meant line 73 to ignore.

I know if I take out bracket on line 72 I get more errors. Or if I move it.

It's an extra bracket. You don't want it. You'll end up with exactly one fewer error in that file than you had before. That one error that is removed is the one you posted. You're saying you get MORE errors if you take it out?

So?

What are they? Try to fix them as well.

The errors are pretty much this:

>javac OrderedList.java
OrderedList.java:54: cannot find symbol
symbol : variable myList
location: class OrderedList<E>
return myList.iterator();
^
OrderedList.java:57: cannot find symbol
symbol : variable myList
location: class OrderedList<E>
return myList.size();
^
OrderedList.java:60: cannot return a value from method whose result type is void
return myList.remove();
^
OrderedList.java:67: cannot find symbol
symbol : variable myList
location: class OrderedList<E>
if (obj.compareTo(myList.next() >= 0 && obj.compareTo(myList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable myList
location: class OrderedList<E>
if (obj.compareTo(myList.next() >= 0 && obj.compareTo(myList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(myList.next() >= 0 && obj.compareTo(myList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(myList.next() >= 0 && obj.compareTo(myList.next()) < 0));
^
OrderedList.java:68: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:68: cannot find symbol
symbol : variable iter
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:69: missing return value
return;
^
10 errors
>Exit code: 1 Time: 0.613

I thought on a wim chaging the myList too theList might make a difference but I get these errors:

>javac OrderedList.java
OrderedList.java:54: incompatible types
found : java.util.Iterator<E>
required: java.util.ListIterator<E>
return theList.iterator();
^
OrderedList.java:60: cannot return a value from method whose result type is void
return theList.remove();
^
OrderedList.java:67: cannot find symbol
symbol : method next()
location: class java.util.LinkedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : method next()
location: class java.util.LinkedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:68: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:68: cannot find symbol
symbol : variable iter
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:69: missing return value
return;
^
9 errors
>Exit code: 1 Time: 0.613

If I write the same program this way I get 5 errors instead:

import java.util.*;
/** A class to represent an ordered list. The data is stored in a linked
*   list data field.
*   @author Koffman & Wolfgang
*/
public class OrderedList<E extends Comparable<E>>
         implements Iterable<E> {
     /** A linked list to contain the data. */
     private LinkedList<E> theList = new LinkedList<E>();
   public OrderedList() {
     theList = new LinkedList < E > ();
   }
   /** Insert obj into the list preserving the list?s order.
       pre: The items in the list are ordered.
       post: obj has been inserted into the list
       such that the items are still in order.
       @param obj The item to be inserted
    */
   public void add(E obj) {
     ListIterator < E > iter = theList.listIterator();
     // Find the insertion position and insert.
     while (iter.hasNext()) {
       if (obj.compareTo(iter.next()) < 0) {
         // Iterator has stepped over the first element
         // that is greater than the element to be inserted.
         // Move the iterator back one.
         iter.previous();
         // Insert the element.
         iter.add(obj);
         // Exit the loop and return.
         return;
       }
     }
     // assert: All items were examined and no item is larger than
     // the element to be inserted.
     // Add the new item to the end of the list.
     iter.add(obj);
   }
   /** Returns the element at the specified position.
       @param index The index of the specified position
       @return The element at position index
    */
   E get(int index) {
     return theList.get(index);
   }
/**** EXERCISE ****/
// Modifier Methods

public ListIterator<E> iterator(){
   ListIterator < E > iter = theList.listIterator();
   return iter ;
}

public int size(){
   return theList.size();
}

public void remove(E obj){
}
public OrderedList<E> getSubList(E obj1, E obj2){
   ListIterator < E > iter = theList.listIterator();
   subList = new LinkedList<E> ();
   if (iter >= obj1 && iter<= obj2){
   subList.add(iter);
   return subList;
}
}
}


>javac OrderedList.java
OrderedList.java:62: cannot find symbol
symbol  : variable subList
location: class OrderedList<E>
   subList = new LinkedList<E> ();
   ^
OrderedList.java:63: operator >= cannot be applied to java.util.ListIterator<E>,E
   if (iter >= obj1 && iter<= obj2){
            ^
OrderedList.java:63: operator <= cannot be applied to java.util.ListIterator<E>,E
   if (iter >= obj1 && iter<= obj2){
                           ^
OrderedList.java:64: cannot find symbol
symbol  : variable subList
location: class OrderedList<E>
   subList.add(iter);
   ^
OrderedList.java:65: cannot find symbol
symbol  : variable subList
location: class OrderedList<E>
   return subList;
          ^
5 errors
>Exit code: 1    Time: 0.613

I thought on a wim chaging the myList too theList might make a difference but I get these errors:

>javac OrderedList.java
OrderedList.java:54: incompatible types
found : java.util.Iterator<E>
required: java.util.ListIterator<E>
return theList.iterator();
^
OrderedList.java:60: cannot return a value from method whose result type is void
return theList.remove();
^
OrderedList.java:67: cannot find symbol
symbol : method next()
location: class java.util.LinkedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : method next()
location: class java.util.LinkedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:67: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
if (obj.compareTo(theList.next() >= 0 && obj.compareTo(theList.next()) < 0));
^
OrderedList.java:68: cannot find symbol
symbol : variable obj
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:68: cannot find symbol
symbol : variable iter
location: class OrderedList<E>
iter.add(obj);
^
OrderedList.java:69: missing return value
return;
^
9 errors
>Exit code: 1 Time: 0.613

But the one error you originally posted went away without other new ones popping up, right? Is this the whole package/project or are there other files?

The error messages on lines 60 and 69 are the most obvious. Your return statement type must match the type that the function said it was going to return. So a void function can't return a value and a non-void function can't do this:

return;

Its the whole package/project.

I've been trying out different versions.

import java.util.*;
/** A class to represent an ordered list. The data is stored in a linked
* list data field.
* @author Koffman & Wolfgang
*/
public class OrderedList<E extends Comparable<E>>
implements Iterable<E> {
/** A linked list to contain the data. */
private LinkedList<E> theList = new LinkedList<E>();
public OrderedList() {
theList = new LinkedList < E > ();
}
/** Insert obj into the list preserving the list?s order.
pre: The items in the list are ordered.
post: obj has been inserted into the list
such that the items are still in order.
@param obj The item to be inserted
*/
public void add(E obj) {
ListIterator < E > iter = theList.listIterator();
// Find the insertion position and insert.
while (iter.hasNext()) {
if (obj.compareTo(iter.next()) < 0) {
// Iterator has stepped over the first element
// that is greater than the element to be inserted.
// Move the iterator back one.
iter.previous();
// Insert the element.
iter.add(obj);
// Exit the loop and return.
return;
}
}
// assert: All items were examined and no item is larger than
// the element to be inserted.
// Add the new item to the end of the list.
iter.add(obj);
}
/** Returns the element at the specified position.
@param index The index of the specified position
@return The element at position index
*/
E get(int index) {
return theList.get(index);
}
/**** EXERCISE ****/
// Modifier Methods

public ListIterator<E> iterator(){
ListIterator < E > iter = theList.listIterator();
return iter ;
}

public int size(){
return theList.size();
}

public void remove(E obj){
}
public OrderedList<E> getSubList(E obj1, E obj2){
ListIterator < E > iter = theList.listIterator();
subList = new LinkedList<E> ();
if (iter >= obj1 && iter<= obj2){
subList.add(iter);
return subList;
}
}
}


>javac OrderedList.java
OrderedList.java:62: cannot find symbol
symbol : variable subList
location: class OrderedList<E>
subList = new LinkedList<E> ();
^
OrderedList.java:63: operator >= cannot be applied to java.util.ListIterator<E>,E
if (iter >= obj1 && iter<= obj2){
^
OrderedList.java:63: operator <= cannot be applied to java.util.ListIterator<E>,E
if (iter >= obj1 && iter<= obj2){
^
OrderedList.java:64: cannot find symbol
symbol : variable subList
location: class OrderedList<E>
subList.add(iter);
^
OrderedList.java:65: cannot find symbol
symbol : variable subList
location: class OrderedList<E>
return subList;
^
5 errors
>Exit code: 1 Time: 0.613

Hi dude
The problem is extra closing brace at end .
You get lot error messages when you remove the brace because the compiler actually go inside of the code after you remove the bracket.

Well i fixed you code and also command to say what is the problem
Go thru it

import java.util.*;

/** A class to represent an ordered list. The data is stored in a linked
*   list data field.
*   @author Koffman & Wolfgang
*/

public class OrderedList<E extends Comparable<E>>
        implements Iterable<E> {
    /** A linked list to contain the data. */
    private LinkedList<E> theList = new LinkedList<E>();

  public OrderedList() {
    theList = new LinkedList < E > ();
  }

  /** Insert obj into the list preserving the lists order.
      pre: The items in the list are ordered.
      post: obj has been inserted into the list
      such that the items are still in order.
      @param obj The item to be inserted
   */
  public void add(E obj) {
    ListIterator < E > iter = theList.listIterator();
    // Find the insertion position and insert.
    while (iter.hasNext()) {
      if (obj.compareTo(iter.next()) < 0) {
        // Iterator has stepped over the first element
        // that is greater than the element to be inserted.
        // Move the iterator back one.
        iter.previous();
        // Insert the element.
        iter.add(obj);
        // Exit the loop and return.
        return;
      }
    }
    // assert: All items were examined and no item is larger than
    // the element to be inserted.
    // Add the new item to the end of the list.
    iter.add(obj);
  }

  /** Returns the element at the specified position.
      @param index The index of the specified position
      @return The element at position index
   */
  E get(int index) {
    return theList.get(index);
  }

/**** EXERCISE ****/
    public ListIterator <E> iterator(){
        return (ListIterator<E>) theList.iterator();//not myList it should be theList
    }
    public int size(){
        return theList.size();   //not myList it should be theList
    }
    public void remove(E obj){
        theList.remove(obj);//not myList it should be theList and there should not any return value see it is void
    }


    public OrderedList<E> getSubList(E obj1, E obj2){
                        OrderedList<E>subList = new OrderedList< E >();
         //LinkedList<E> YourList = new LinkedList<E>();

        // if (obj1.compareTo(theList.next() >= 0 && obj2.compareTo(theList..next()) < 0));
        //iter.add(obj);            
        /*
         * you did not create any iterator here so no way to use it 
         * so here i chage entire code hopes it satisfy you
         */
           Iterator<E> i = theList.iterator();
           E o;
           while(i.hasNext()){
                o = i.next();
                if((obj1.compareTo(o)>=0) && (obj2.compareTo(o)<0)){
                    subList.add(o);
                }
           }
            return subList; 

        } 
}

Well I now only have these errors:


OrderedList.java:63: operator >= cannot be applied to java.util.ListIterator<E>,Eif (iter >= obj1 && iter<= obj2){^OrderedList.java:63: operator <= cannot be applied to java.util.ListIterator<E>,Eif (iter >= obj1 && iter<= obj2){^OrderedList.java:64: cannot find symbolsymbol : variable subListlocation: class OrderedList<E>subList.add(iter);^OrderedList.java:65: cannot find symbolsymbol : variable subListlocation: class OrderedList<E>return subList;^5 errors>Exit code: 1 Time: 0.613

Learn to read and interpret error messages, and learn how to fix them.
We're NOT here to do all your work for you, not now and certainly not forever.

Learn to read and interpret error messages, and learn how to fix them.
We're NOT here to do all your work for you, not now and certainly not forever.

I know that I'm doing the best I can. I'm just posting the error messages so people see what I'm seeing.

You probably saw the second version of the program that I posted that basically cut the amount of problems I had in half. And then I saw a stupid mistake that I over looked that took my errors down too 4 instead of 10.

I understand your point of view, and I can see how from my posts it looks like I'm just compiling the program and saying fix these errors. I'm compiling them and then showing you what I get as a result and then I start working on them after posting.

hi dude
What version of jdk you use

Update 4 version.

Thank you for your help suresh111_mca. I would also like to thank VernonDozier for helping me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.