public class MyArray
{
private String[] array;
private int capacity,count;
private boolean sorted; // keeps track of whether theArray is currently sorted or unsorted
public MyArray( int initialCapacity )
{
// YOUR CODE HERE
}
// Appends the specified String to the end of theArray.
// UNLIKE ArrayList, our add does NOT return true. Our version is void
public void add( String s )
{
// YOUR CODE HERE
}
// Returns true if theArray contains the specified String.
public boolean contains( String s )
{
// YOUR CODE HERE
return true; // Just to make it compile. you change as needed
}
// returns the String at theArray[index]
// must throw newRuntimeException("MyArray::get() No element at index " + index" )
// if index is invalid. i.e. index<0 || index >= count;
public String get( int index )
{
return null; //Just to make it compile. you change as needed
}
// assigns incoming s into theArray[index]
// UNLIKE ArrayList, our set does NOT return the String assigned in. Our version is void
// must throw newRuntimeException("MyArray::set() No element at index " + index" )
// if index is invalid. i.e. index<0 || index >= count;
public void set( int index, String s )
{
// YOUR CODE HERE
}
// returns index location of s inside theArray or returns -1 if not found
public int indexOf( String s )
{
// YOUR CODE HERE
// use Arrays.binarySearch() if theArray is currently in sorted order
// otherwise you are stuck doing you own linearSearch
return -1; //Just to make it compile. you change as needed
}
// returns true if the count is zero
public boolean isEmpty()
{
// YOUR CODE HERE
return true; //Just to make it compile. you change as needed
}
// removes the string at theArray[index]
// UNLIKE ArrayList, our remove does NOT return ref to that removed string
// must throw newRuntimeException("MyArray::remove() No element at index " + index" )
// if index is invalid. i.e. index<0 || index >= count;
public void remove( int index )
{
// YOUR CODE HERE
}
// returns ref to a DEEP COPY of theArray
public String[] toArray()
{
// YOUR CODE HERE
return null; // Just to make it compile. you change as needed
}
// sorts theArray of Strings
// Call Arrays.sort() DO NOT WRITE YOUR OWN SORT!
public void sortMe()
{
// YOUR CODE HERE
}
} //END MyArray