正如标题所说,我必须提出一个管理学生的申请。学生被组织成小组。学生必须从文本文件中编写,每个文本文件都是成组进行的。如果我每组限制30名学生,那么对于60名学生,我将有2个小组。作为Java的新手,我真的不知道如何在达到30名学生后增加组ID,或者,我不知道办法。我在想地图或类似的东西。这是我到目前为止所做的。有什么建议吗?
学生班级:
public class Student {
private String firstName;
private String lastName;
private int age;
private String CNP;
private int grade;
private boolean leader;
public Student(String firstName, String lastName, int age, String CNP, int grade, boolean leader) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
this.CNP = CNP;
this.grade = grade;
this.leader = leader;
}
}
师资班:
public class Faculty {
private int groupIterator;
private List<Student> list;
public Faculty() throws Exception {
list = new ArrayList<Student>();
Scanner fileIn = new Scanner(new File("---"));
String line;
String firstName;
String lastName;
int age;
String CNP;
int grade;
boolean leader;
while(fileIn.hasNextLine()) {
line = fileIn.nextLine();
firstName = line;
line = fileIn.nextLine();
lastName = line;
line = fileIn.nextLine();
age = Integer.parseInt(line);
line = fileIn.nextLine();
CNP = line;
line = fileIn.nextLine();
grade = Integer.parseInt(line);
line = fileIn.nextLine();
leader = Boolean.parseBoolean(line);
list.add(new Student(firstName,lastName,age,CNP,grade,leader));
}
fileIn.close();
}
一只萌萌小番薯
皈依舞
相关分类