I have to create an array of objects to then be randomly filled. In this array I need to put 100 random, Person(base) Student(sub), Professor(sub), Course(an array of Student plus a Professor), and a Circle(unrelated). I also have to name and count every Person(including profs and students) I enter into the array.
Object[] array = new Object[100];
String[] names = new String[]{"Ben","Anne","Joe","Sue","John","Betty","Robert","Mary",
"Mark","Jane","Paul","Willow","Alex","Courtney","Jack",
"Rachel"};
int count = 0;
for(int i=0; i<100; i++){
int a = (int)(Math.random()*5);
String n = names[(int)(Math.random()*16)];
if(a == 0){array[i]= new Person(n); count++;}
else if(a == 1){array[i]= new Student(n); count++;}
else if(a == 2){array[i]= new Professor(n); count++;}
else if(a == 3){
array[i]= new Course();
count = count + 11;
for(int j = 0; j<10; j++){
String l = names[(int)(Math.random()*16)];
array[i].getClasslist()[j].setName(l);}
}
else if(a == 4){array[i]= new Circle();}
}
Whenever I try to call a method of one of the members, however, it tells me "Cannot find Symbol- Method getClasslist()" or setName or whatever I'm trying to call. Any idea how to fix this?