管理教职员工中学生的应用程序

正如标题所说,我必须提出一个管理学生的申请。学生被组织成小组。学生必须从文本文件中编写,每个文本文件都是成组进行的。如果我每组限制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();

}


函数式编程
浏览 68回答 2
2回答

一只萌萌小番薯

就目前而言,您的代码对于所扮演的角色感到困惑。它似乎代表了一个老师和他们的学生的课堂。但是,它还具有解析传入学生所需的代码。这将是一个糟糕的设计选择。Faculty最好的OOP方法是有一个类。这基本上代表了将学生与老师放在一起的学校实体。它将解析将学生放入课堂的文件。RegistrarFaculty该类应该有一个方法(),该方法将用于确定新学生是否需要新学生,因为前一个已满。然后,注册官将创建一个新的学院并重复该过程。FacultyisClassFullstudents.size >= 30RegistrarFacultyFaculty最终结果将是一个列表,其列表最多为 30 。RegistrarFacultyStudent由于这似乎是一个学生练习,我将把实现留给你,但希望这能弄清楚如何在代码中表示这个概念。

皈依舞

学生:public class Student {private String firstName;private String lastName;private int age;private String CNP;private int grade;private boolean leader;private int group;public Student(String firstName, String lastName, int age, String CNP, int grade, boolean leader, int group) {&nbsp; &nbsp; this.firstName = firstName;&nbsp; &nbsp; this.lastName = lastName;&nbsp; &nbsp; this.age = age;&nbsp; &nbsp; this.CNP = CNP;&nbsp; &nbsp; this.grade = grade;&nbsp; &nbsp; this.leader = leader;&nbsp; &nbsp; this.group = group;}能力:public class Faculty {private int groupIterator;private List<Student> list;public Faculty() throws Exception {&nbsp; &nbsp; list = new ArrayList<Student>();&nbsp; &nbsp; Scanner fileIn = new Scanner(new File("---"));&nbsp; &nbsp; String line;&nbsp; &nbsp; String firstName;&nbsp; &nbsp; String lastName;&nbsp; &nbsp; int age;&nbsp; &nbsp; String CNP;&nbsp; &nbsp; int grade;&nbsp; &nbsp; boolean leader;&nbsp; &nbsp; while(fileIn.hasNextLine()) {&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; firstName = line;&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; lastName = line;&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; age = Integer.parseInt(line);&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; CNP = line;&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; grade = Integer.parseInt(line);&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; line = fileIn.nextLine();&nbsp; &nbsp; &nbsp; &nbsp; leader = Boolean.parseBoolean(line);&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; // Here's the key bit - we now pass in the group id based on the list size&nbsp; &nbsp; &nbsp; &nbsp; list.add(new Student(firstName,lastName,age,CNP,grade,leader,len(list)/30));&nbsp; &nbsp; }&nbsp; &nbsp; fileIn.close();}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java