aspose file tools*
The moose likes Beginning Java and the fly likes test bed for array based list implementation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "test bed for array based list implementation" Watch "test bed for array based list implementation" New topic
Author

test bed for array based list implementation

Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
I would like to know how to print a list without destroying the list, and also to check each of the methods. All of my attempts have failed. Can anyone help, please. Currently using the method
Public void print( )
{
if (isEmpty( )) System.out.println("( )");
else
{
System.out.print("( ");
For (setFirst( ); isInList( ); next( ) )
System.out.print(currValue( ) + " ");
System.out.println(" ) ");
}
}
Destroys the list when executed.
I would also like to test the following methods individually in the main.
public void clear( ); // Remove all Objects from list
public void insert(Object item); // Insert Object at curr position
public void append(Object item); // Insert Object at tail of list
public Object remove( ); // Remove/return current Object
public void setFirst( ); // Set current to first position
public void next( ); // Move current to next position
public void prev( ); // Move current to prev position
public int length( ); // Return current length of list
public void setPos(int pos); // Set current to specified pos
public void setValue(Object val); // Set current Object's value
public Object currValue( ); // Return value of current Object
public boolean isEmpty( ); // Return true if list is empty
public boolean isInList( ); // True if current is within list
public void print( ); // Print all of list's elements

[This message has been edited by Ronald Pruitt (edited January 20, 2001).]
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Can you please print the rest of your List class? Please read the FAQ to learn how to format your code so it's readable.
Thanks,
-Peter
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32

I hope this is right. I checked the FAQs and I'm still not sure if this is what you want. I sure don't want to be clogging up the system.
[This message has been edited by Ronald Pruitt (edited January 20, 2001).]
[This message has been edited by Ronald Pruitt (edited January 20, 2001).]
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Ronald,
First, good job on following the FAQ and formatting your code so I can read it.
Okay. A couple of things.
1. Why are you providing an implementation for the List interface? You're missing an import java.util.* or java.util.List statement. Once I added that import, it turns out that you're missing a lot of methods (e.g. size(), contains(), iterator(), etc.) If you don't provide these other methods in the List interface, java requires you to declare your AList class as abstract.
2. Can't you use the ArrayList() implementation? This is the JDK collections framework implementation of the List interface. It's pretty well written. If you want, you can look the the source and see how the SUN engineer's implemented the List interface.
3. Are you bored and you want to do this an exercise? Is this for a class and the professor is just one sadistic person that he actually assigned this as a homework assignment?
4. You should start using some of the coding conventions to make your life easier in the future. For starters, you might want to reformat your method comment so that the javadoc utility can generate HTML help files similar to the JDK documentation. To do this, you need to use /** */ E.g.

I would look into using the Collections Framework. What you're proposing to do is a lot of work that has already been done for you.
-Peter
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Ronald,
Copy your List interface here.
Thanks,
-Peter
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32

In addition I must implement

and make a method that if a word is being added to a list and that word is the same as the Current(logical) current word, the count should be incremented rather than a separate instance of the word being add.
This is what I've done so far, not sure but I think some of it is right, it seems to give me the right answers.

Thanks,
-Peter[/b]
</BLOCKQUOTE>
[This message has been edited by Ronald Pruitt (edited January 21, 2001).]
[This message has been edited by Ronald Pruitt (edited January 21, 2001).]
[This message has been edited by Ronald Pruitt (edited January 21, 2001).]
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Ronald,
It looks like you have a good handle on the problem. It's been a long weekend, so you're going to have to remind me again what problem you're having with this assignment?
-Peter
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
Originally posted by Peter Tran:
Ronald,
It looks like you have a good handle on the problem. It's been a long weekend, so you're going to have to remind me again what problem you're having with this assignment?
-Peter

Need a method that would check to see if a word being added to a list is already in the list at the current position
and if so to increment the list count but not add the word. Don't know how to do this. I have method to append
the list, would it be better to write some sort of if statement for these methods instead.


in the main
L2.append(new WordElem("Mountain", 5));
want to append the list, check to see if the item that is being added is at the current position(end of the list) and if so increment the count only.
thanks
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
Ronald,
Good. I can handle one problem at a time which is what you gave me. I'm glad you were reading my mind. If you stated two problems my brain would have probably self-imploded which would have been a bad thing to do on a Monday. (Trust me, it's not a pretty site either. )
Enough rambling, and to your problem. To keep a counter of what has already appeared in your list, I would create an inner class containing your Object and a counter. This would be stored in the array.

I'm going to cop out and make you write the findObject() method to find the object in the elementArray.
-Peter
Ronald Pruitt
Ranch Hand

Joined: Jan 15, 2001
Posts: 32
thanks for all your help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: test bed for array based list implementation