Hi,
I'm still new to
Java, and get a bit lost sometimes implementing simple stuff.
I am writing a class that defines an array, and needs to have two constructors, one that takes no parameters and creates an empty list, and another that takes the name of a text file as a parameter and creates a list containing the numbers listed in the text file.
I have also added a method that adds a new number to the list at any time. However, I need a boolean method that returns 'true' if the list contains the given number and 'false' otherwise. The problem is, I'm not sure how to implement this correctly.
Also, how do I construct a toString method that will return a
string representing the numbers in the list.
My code so far is as follows:
package
testing;
import simplejava.SimpleReader;
public class NumberList {
int [] numbers;
int arraySize, size;
public NumberList()
{
int[] numbers = new int[10000];
arraySize = 10000;
size = 0;
}
public NumberList(String fileName)
{ SimpleReader file = new SimpleReader(fileName);
size =0;
int next = file.readInt();
while (!file.finished())
{ size++;
next = file.readInt();
}
file = new SimpleReader(fileName);
numbers = new int[size];
arraySize = size;
for (int i = 0; i<size; i++)
numbers[i] = file.readInt();
}
public void add(int next)
{
numbers[size] = next;
size++;
}
}
Any help would be appreciated!!!
