zoukankan      html  css  js  c++  java
  • 软工实践结对作业-黄紫仪

    一:代码:git代码(exe文件还没折腾出来QAQ)

    二:结对:031502313黄紫仪(0.0是的没错单刷了……)

    三:代码相关注释

    相关代码: 

    部门类

    public class Department {

    private int tId;
    private String tName; //部门名
    private int sectionMax; //区间最大值  
    private int sectionRest; //剩下的招募数
    private List<Student> myStudent = new ArrayList<Student>(); //拉进来的学生队列
    private int[] nCharacter=new int[2]; //需求的兴趣(数组内的数字为需求兴趣点)
    private int[] nTime=new int[3];//需求的时间段(跟上面差不多)

    学生类

    public class Student {
    private String sName;
    private float gradePoint;
    private int[] sapplication = new int[5];//志愿申请
    private int departmentCount;//已经加入的部门数
    private float composite;//综合分
    private int[] time =new int [10];//空闲时间段=0为空。
    private int[] character =new int[5];//兴趣点。=1说明拥有
    public Student() {

    }

     

    相关创建函数

    public class CreateMember {
    public String createStudentName(){
    String stringBase = "abcdefghijklmnopqrstuvwxyz";
    Random random = new Random();
    StringBuffer studentName = new StringBuffer();
    for (int i = 0; i < 4; i++) {
    int number = random.nextInt(stringBase.length());
    studentName.append(stringBase.charAt(number));
    }
    return studentName.toString();
    }

    public float createGradePoint(){
    Random random = new Random();
    float gradePoint = random.nextFloat()*4+1;
    gradePoint = (float) ((int)((gradePoint*100+5))/100.0);
    return gradePoint;
    }

    创建申请
    public int[] creatApplication(){
    int[] application = new int[5];
    Random random = new Random ();
    boolean[] bool = new boolean[20];
    int randInt = 0;

    for(int i = 0; i < 5 ; i++) {
    do{
    randInt = random.nextInt(20);
    }while(bool[randInt]);
    bool[randInt] = true;
    application[i]=randInt+1;
    }
    return application;
    }

    创建兴趣点
    public int[] creatCharacter(){
    int[] application = new int[5];
    Random random = new Random ();
    boolean[] bool = new boolean[5];
    int randInt = 0;

    for(int i = 0; i < 3 ; i++) {
    do{
    randInt = random.nextInt(5);
    }while(bool[randInt]);
    bool[randInt] = true;
    application[randInt]=1;
    }
    return application;
    }
    创建需求兴趣点
    public int[] creatnCharacter(){
    int[] application = new int[2];
    Random random = new Random ();
    boolean[] bool = new boolean[5];
    int randInt = 0;

    for(int i = 0; i < 2 ; i++) {
    do{
    randInt = random.nextInt(5);
    }while(bool[randInt]);
    bool[randInt] = true;
    application[i]=randInt;
    }
    return application;
    }

    创建空闲时间
    public int[] creatTime(){
    int[] application = new int[10];
    Random random = new Random ();
    boolean[] bool = new boolean[10];
    int randInt = 0;

    for(int i = 0; i < 3 ; i++) {
    do{
    randInt = random.nextInt(10);
    }while(bool[randInt]);
    bool[randInt] = true;
    application[randInt]=1;
    }
    return application;
    }
    创建需求时间段
    public int[] creatnTime(){
    int[] application = new int[3];
    Random random = new Random ();
    boolean[] bool = new boolean[10];
    int randInt = 0;

    for(int i = 0; i < 3 ; i++) {
    do{
    randInt = random.nextInt(10);
    }while(bool[randInt]);
    bool[randInt] = true;
    application[i]=randInt;
    }
    return application;
    }
    创建学生名单
    public List<Student> createAllStudent(){
    CreateMember cm = new CreateMember();
    List<Student> studentList= new ArrayList<Student>();
    for(int i=0;i<300;i++){
    Student s = new Student();
    s.setsName(cm.createStudentName());
    s.setGradePoint(cm.createGradePoint());
    s.setSapplication(cm.creatApplication());
    s.setdepartmentId(cm.creatdepartmentId());
    s.setComposite(0);
    s.setdepartmentCount(0);
    s.settime(cm.creatTime());
    s.setCharacter(cm.creatCharacter());
    studentList.add(s);

    }
    return studentList;
    }

     


    private int[] creatdepartmentId() {
    int[] application = new int[5];

    return application;
    }

    public String createTeacherName(){

    String stringBase = "abcdefghijklmnopqrstuvwxyz";
    Random random = new Random();
    StringBuffer teacherName = new StringBuffer();
    for (int i = 0; i < 4; i++) {
    int number = random.nextInt(stringBase.length());
    teacherName.append(stringBase.charAt(number));
    }
    return teacherName.toString();

    }

    public int createSectionMax(){
    Random random = new Random();
    int sectionMax = random.nextInt(6)+10;
    return sectionMax;
    }

    创建部门名单

    public List<Department> createAllTeacher(){
    CreateMember cm = new CreateMember();
    List<Department> departmentList= new ArrayList<Department>();
    for(int i=1;i<=20;i++){
    Department t = new Department();
    t.settId(i);
    t.settName(cm.createTeacherName());
    int temp = cm.createSectionMax();
    Global.countAll+=temp;
    t.setSectionMax(temp);
    t.setSectionRest(temp);
    t.setnTime(cm.creatnTime());
    t.setnCharacter(cm.creatnCharacter());
    departmentList.add(t);
    }
    return departmentList;
    }
    }

     

    判断函数:

    设置迭代器,按照每一轮的志愿对学生队列进行扫描,并且归分到部门的临时队列,按照综合分进行排序,然后根据剩余部分人数去取排名。超出部分剔除,少人的话则修改人数上限

    public void allocteStudent(int round, float g, float v,float c) {
    int checked = 0;int C=0;
    Iterator departmentIterator = Global.departmentList.iterator();

    while(true) {
    while(departmentIterator.hasNext()) {
    Department department = (Department)departmentIterator.next();
    List<Student> tempStudentList = new ArrayList();
    List<Student> countStudentList = new ArrayList();
    Iterator var10 = Global.studentList.iterator();

    Student student;
    while(var10.hasNext()) {
    student = (Student)var10.next();
    int[] application = student.getSapplication();
    if (application[round] == department.gettId()) {
    tempStudentList.add(student);
    }
    }

    var10 = tempStudentList.iterator();

    while(var10.hasNext()) {
    student = (Student)var10.next();
    GetTempComposite gtp = new GetTempComposite();
    int[] tempComposite = new int[2];//用来储存时间&兴趣匹配的分数点
    tempComposite = gtp.getComposite(student, round);
    float composite = 0.0F;
    float gradePoints = 0.0F;
    gradePoints = student.getGradePoint();//获取绩点
    composite = gradePoints * g + tempComposite[0]* v+tempComposite[1]*c;//计算综合分
    student.setComposite(composite);
    }

    Collections.sort(tempStudentList, new sortbypoint());
    int sectionCurrent = department.getSectionRest();
    if (tempStudentList.size() >= sectionCurrent) {//超出人数,就取前面上限人数加入队列
    List<Student> myStudentList = new ArrayList();
    for (int i = 0; i < sectionCurrent; i++) {
    Student s = tempStudentList.get(i);

    myStudentList.add(s);
    department.addStudent(s);
    //修改学生加入的部门数
    C=s.getdepartmentCount();
    C++;
    //如果部门数=1,说明是刚加入的,计算进选择了部门的学生人数
    if(C==1)
    {Global.countStu++;}
    s.setdepartmentCount(C);
    tempStudentList.set(i,s);
    ++checked;
    }

    //人数不达到部门上限,则加入队列修改上限

    sectionCurrent -= sectionCurrent;
    department.setSectionRest(sectionCurrent);
    Global.doneDepartmentList.add(department);
    departmentIterator.remove();
    } else {
    sectionCurrent -= tempStudentList.size();
    department.setSectionRest(sectionCurrent);

    for(int i = 0; i < tempStudentList.size(); ++i) {

    Student s = (Student)tempStudentList.get(i);
    department.addStudent(s);
    C=s.getdepartmentCount();
    C++;
    s.setdepartmentCount(C);
    tempStudentList.set(i,s);

    if(C==1)
    Global.countStu++;
    ++checked;
    }
    }
    }

    return;
    }
    }

    选择优先条件://根据输入的数字(1,2,3)来确定相对应的优先条件。1.绩点,2.时间,3.兴趣

    do {
    Global.countAll = 0;
    Global.departmentList = cm.createAllTeacher();
    } while(Global.countAll < 100);
    float g = 0.2f;
    float v = 0.2f;
    float c = 0.2f;
    System.out.println("输入优先类型:" );
    Scanner sr = new Scanner(System.in);//初始化scanner对象
    int num = sr.nextInt();
    do
    {switch(num)
    { case 1:g=0.6f;break;
    case 2:v=0.6f;break;
    case 3:c=0.6f;break;
    default: System.out.println("输入错误请重新输入:" );num = sr.nextInt();}
    }
    while(num!=1&&num!=2&&num!=3);
    Global.studentList = cm.createAllStudent();
    Global.doneDepartmentList = new ArrayList<>();
    System.out.println("部门限选总人数:" + Global.countAll);
    System.out.println("部门总数:" + Global.departmentList.size());
    System.out.println("学生总数:" +Global.studentList.size());

    Distribution distribution = new Distribution();

     

    结果截图

     部分学生结果:

     

     

     部分部门结果

     心得:感觉这回写的略简略(连前言都没了),可能是放风了半天才写的所以感受啥的有点忘记了。不过吐槽一下这回的结对作业……比之前那个大的更多了啊。。。。各种函数设计起来就十分头疼。而且出于某些原因代码是用的JAVA,虽然说很多部分跟结构都跟C++类似,但是之前没怎么接触过确实还是有点头疼。

        整体思路的话呢,首先是条件的判定。3种判断上每个点都会相关涉及到,只是比例不是很相同,一方面这样可以杜绝一些因为某些部分不匹配导致部门人数不够。另一方面,感觉每个点其实或多或少都会影响到部门的选择,所以还是尽量都参与到其中。然后时间跟兴趣点来说,一个点对应匹配上是2分。比例系数初始是0.2,被选为优先条件的会修改成0.6,这样可以保证在优先条件确定时,对应的部分能起到相对绝对的确定作用。

         然后是生成对应的类,以及整个判定流程的设定。这部分参考了之前前届学长们的相关思路,用了迭代器(虽然并不是很懂是个啥具体功能),根据每一轮志愿去分学生队列,将其加入每一个社团的分队列,然后计算对应的综合分,排序。取上限人数。少于上限的话,就先加入队列,然后修改上线人数。每次加入一个部门后会对加入部门数进行修改,当部门数==1的时候说明是刚才始加入第一个部门,则纳入部门学生人数的统计里面。反之直接无视。这样可以保证每一个学生都有可能,报好几个社团。

        最后是输出部分,整个输出要写入文件所以又开始了新一波的百度(操作台处理的话可以实现)。整了半天才算是基本完成。(但是到现在我都不知道怎么才能把JAR弄出来打包成exe啊!就十分头疼)

        不得不说,这回单刷起来真的是十分辛苦。深刻感受到了合作的重要性(QAQ被队友拖了N天实在是忍无可忍我也是没办法真的!)。不过感觉自学能力跟变通能力也是噌噌噌的往上涨啊。希望下拨实验不要那么变态了吧(加班N天到想打人。躺平了……QAQ)

        

  • 相关阅读:
    WDF CSS 书写规范
    瞬间之美web界面设计如何让用户心动 读后感(一)
    ubuntu install node0.8.9 to the current user
    js单元测试_jsTestDriver
    window.print
    Java内省
    jQuery源代码学习jQuery对象扩展
    jdk集合结构
    【转载】程序员(1)
    【装载】JAVA虚拟机的内存模型
  • 原文地址:https://www.cnblogs.com/huangziyi/p/7658552.html
Copyright © 2011-2022 走看看