Sorry about the lack of info
any way here is the error if i set the array size 10.
Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at arrays.Storage.addStudent(Student.java:69)
at arrays.StudentTest.main(StudentTest.java:19)
this happens after i have added five new names to the array
here is the add method i have:
public void addStudent(Student studentObj, int count)
{
int hash = studentObj.hashCode(numOfStudents);
int index = 0;
boolean add = false;
if (students[hash] != null)
{
while (students[hash] != null && hash < students.length)
{
++hash;
System.out.println("++i");
}
students[hash] = studentObj;
}
else
{
students[hash] = studentObj;
}
and the
test:
class StudentTest
{
public static void main(String[] args)
{
int maxNum = 10;
Storage store = new Storage(maxNum);
for (int i = 0; i < store.getSize(); i++)
{
Student name = new Student(JOptionPane.showInputDialog(
"please enter a name!").toUpperCase(), JOptionPane
.showInputDialog("please enter a course!")
.toUpperCase());
store.addStudent(name, maxNum);
}
System.out.println("Student name\tStudent course");
System.out.println("------------\t--------------");
for (int i = 0; i < store.getSize(); i++)
{
System.out.println( store.retrieveList(i).getName() + "\t\t"
+ store.retrieveList(i).getCourse());
}
System.exit(0);
}
}
thanks again