Code:
public class StringList
{
// attributes
private String[] list;
private int total;
// methods
public StringList (int sizeIn)
{
list = new String [sizeIn];
}
public boolean add(String s)
{
if(!isFull())
{
list[total++] = s;
return true;
}
else
{
return false;
}
}
public boolean isEmpty(
{
return total==0;
}
public boolean isFull()
{
return total==list.length;
}
// this is very 'off-by-one'-error prone, you should go for
// zero-based indexing.
public String getItem (int i)
{
return list [i-1];
}
public int getTotal()
{
return total;
}
public boolean remove (int numberIn)
{
// to be completed
}
}
Bookmarks