Archive

Posts Tagged ‘removestring’

Collection Classes

June 14th, 2009 Comments off

I am looking for help with an Assignment I am working on. Let me know if you can help.

Problem Description:

Create a DOS console application that keeps track of a list of names. Your program should be able to add a name, remove a name at the current position, to concatenate two name lists, to retrieve a name from the list, and to print out the whole list of names in the list.

Implementation requirement:

You are going to use two classes to implement this assignment: TestStringArraySeq, StringArraySeq. The TestStringArraySeq is the application driver class and contains the main() method. The StringArraySeq is the worker class. You have to use sequence collection data structure to implement this worker class. The storage data structure for the collection class should be array. In this class, you need to implement the following methods:

StringArraySeq
public StringArraySeq ()
This constructor takes no argument. It initializes the instance variable manyItems to 0; initializes the instance variable currentIndex to 0, and allocates 10 cells for the arrary data.

StringArraySeq
public StringArraySeq (int initialCapacity)
This constructor takes one argument. It first checks to see whether the parameter is positive. If it is negative, the an exception is thrown. It then initializes the instance variable manyItems to 0; initializes the instance variable currentIndex to 0, and allocates initialCapacity number of cells for arrary data.

getManyItems
public int getManyItems ()
This simple method returns the value of instance variable manyItems. Setters and getters are used to enforce information hiding.

setManyItems
public void setManyItems (int m)
This simple method sets the instance variable manyItems to the value passed in.

getCurrentIndex
public int getCurrentIndex ()
This simple method returns the value of instance variable currentIndex.

setCurrentIndex
public void setCurrentIndex (int c)
This simple method sets the instance variable currentIndex to the value passed in.

addAfter
public void addAfter(String element)
addAfter places a new element after the current element. If there is no current element, then the addAfter method places the new element at the end of the sequence. In all cases, when the method finishes, the new element will be the current element.

start
public void start()
this sequence help method sets the current element at the front of the sequence.

isCurrent
public boolean isCurrent()
this is an accessor method used to determine whether this sequence has a current element. It should be called before calling the method getCurrent.

ensureCapacity
public void ensureCapacity(int minimumCapacity)
this help method changes the capacity of the sequence to the minimumCapacity. This method is only needed if the sequence is implemented using array.

toString
public String toString()
This method returns all a String with the names in the sequence class. Each name appears on a separate line.

getCurrent
public String getCurrent()
this is an accessor method used to retrieve the value of current element.

advance
public void advance()
this sequence help method moves forward so that the current element is now the next element in the sequence. Before calling this method, you should call isCurrent() method to make sure that there is a current element. If the current element is the last element, then after calling this method there will be no current element. Otherwise, the new element is the element immediately after the original current element.

removeCurrent
public void removeCurrent()
removeCurrent removes the current element from a sequence. Before invoking this method, you should call isCurrent() to make sure that there is a current element. When this method is called, if the current element is the final element, then after the removal there is no longer a current element; otherwise, the new current element is the one that used to be after the removed element.

concatenation
public static StringArraySeq concatenation(StringArraySeq s1, StringArraySeq s2)
concatenation method creates a new sequence that contains all the elements from the first sequence followed by another. The resulting sequence has no current element. The concatenation is somewhat similar to the union of two bags. This method is implemented with static method. As a general rule, the methods that operate on two collections are usually implemented as static methods. This is because of the reason that static methods are able to handle parameters that are null.

clone
public Object clone()
the clone method returns a copy of this sequence. The return object should have separate memory space. Subsequent changes to the copy will not affect the original, nor vice versa. The return value should be typecast to a StringArraySeq before it is used. Since the current element is not specified, you can set currentIndex of the returned object to any value.

getString
public static String getString(StringArraySeq s, String target)
This method returns the first occurrence of the target string in the sequence class. If there is not such a string, the method returns null. To implement this method, you must use the following methods: start(), isCurrent(), advance(), and getCurrent(). If the target is fund, you should set the currentIndex to the position where the target is; do nothing to the currentIndex otherwise.
Note: you can learn how regular methods use static methods from this.

removeString
public boolean removeString(String target)
This method removes the target string from the sequence class if it exists (first occurrence). The method returns true when the operation is successful and returns false if the operation fails. If the removal is successful, the following element is set to be the current element. If there was no following element, then there is now no current element.
Note: suggest to use getString(), removeCurrent() methods.

You can reference all the methods in the bag collection class and the supplement note 3. Most of the methods of the bag class and of the sequence class are almost identical, but you need to be careful for those that are different.
I suggest you to use the following class instance variables for the sequence class:
data

Categories: Java Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Bear