public class StudentCard {
public static void main(String[] args) {
Student[] students = new Student[100];
for (int i = 0; i < students.length; i++) {
students[i] = new Student(i + 1);
}
for (int k = 0; k < 3; k++) {
int idx = (int) (Math.random() * students.length);
System.out.printf("選んだ学生の添字: %3d, 学生番号: %3d, 成績: %3d%n",idx, students[idx].Id(), students[idx].Score());
}
}
}
class Student {
private int id;
private int score;
public Student(int id) {
this.id = id;
this.score = (int) (Math.random() * 100) + 1;
}
public int Id() {
return id;
}
public int Score() {
return score;
}
}
OOPレポート1

この記事は約2分で読めます。
コメント