オブジェクトの配列を作成して、ランダムに埋める必要があります。この配列には、100 個のランダムな人、学生 (サブ)、教授 (サブ)、コース (学生と教授の配列)、および円 (無関係) を配置する必要があります。また、配列に入力するすべての人 (教授と学生を含む) に名前を付けて数える必要があります。
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();}
}
ただし、メンバーのいずれかのメソッドを呼び出そうとすると、「Symbol-Method getClasslist() が見つかりません」または setName など、呼び出そうとしているものはすべて表示されます。これを修正する方法はありますか?