为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

函数式编程 2022-08-17 10:55:18
正如标题所说,我必须提出一个管理学生的申请。学生被组织成小组。学生必须从文本文件中编写,每个文本文件都是成组进行的。如果我每组限制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();}
查看完整描述

2 回答

?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

就目前而言,您的代码对于所扮演的角色感到困惑。它似乎代表了一个老师和他们的学生的课堂。但是,它还具有解析传入学生所需的代码。这将是一个糟糕的设计选择。Faculty

最好的OOP方法是有一个类。这基本上代表了将学生与老师放在一起的学校实体。它将解析将学生放入课堂的文件。RegistrarFaculty

该类应该有一个方法(),该方法将用于确定新学生是否需要新学生,因为前一个已满。然后,注册官将创建一个新的学院并重复该过程。FacultyisClassFullstudents.size >= 30RegistrarFacultyFaculty

最终结果将是一个列表,其列表最多为 30 。RegistrarFacultyStudent

由于这似乎是一个学生练习,我将把实现留给你,但希望这能弄清楚如何在代码中表示这个概念。


查看完整回答
反对 回复 2022-08-17
?
皈依舞

TA贡献1851条经验 获得超3个赞

学生:


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) {

    this.firstName = firstName;

    this.lastName = lastName;

    this.age = age;

    this.CNP = CNP;

    this.grade = grade;

    this.leader = leader;

    this.group = group;

}

能力:


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);  

        // Here's the key bit - we now pass in the group id based on the list size

        list.add(new Student(firstName,lastName,age,CNP,grade,leader,len(list)/30));

    }


    fileIn.close();

}


查看完整回答
反对 回复 2022-08-17
  • 2 回答
  • 0 关注
  • 67 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信