2018-11-12作业情况

作业情况:

组员 情况 作业质量
肖少伟 完成 A
刘奇 完成 A
谢志林 完成 A
周康 完成 A
郑昊霖 完成 A

作业部分截图:




刘奇


作业要求:
控制台版学生管理系统

学生类(学号、姓名、性别、年龄、成绩)
学生管理类(提供各种对学生的操作)

  1. 录入学生信息(增加一个学生)
  2. 查询所有学生信息
  3. 根据学号查询单个学生信息
  4. 修改学生信息(根据学号)
  5. 查询所有学生信息,按成绩降序排序

要求:每个班仅有10个学位

作业代码:
Studentclass.java:

package day3stu;

public class Studentclass {
    private int ID;
    private String name;
    private String gender;
    private int age;
    private double score;
    
    public Studentclass(int iD, String name, String gender, int age,double score) {
        super();
        ID = iD;
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.score = score;
    }
    
    public Studentclass() {
        super();
    }

    public int getID() {
        return ID;
    }
    public void setID(int iD) {
        ID = iD;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String gender) {
        this.gender = gender;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public double getScore() {
        return score;
    }
    public void setScore(double score) {
        this.score = score;
    }

    @Override
    public String toString() {
        return "学号:" + ID + "姓名" + name + "性别"
                + gender + "年龄" + age + "成绩" + score  ;
    }
    
}

StudentManage.java:

package day3stu;

public class StudentManage {
    Studentclass[] ary = new Studentclass[10];
    int count;
    public void AddStudent(Studentclass s){
        ary[count]=s;
        count++;
    }
    
    public void ShowAllInfo(){
        for(int i=0;i<ary.length;i++){
            if(ary[i]!=null){
                System.out.println(ary[i]);
            }
        }
    }
    public void ShowInfoByNo(int id){
        for (int i = 0; i < ary.length; i++) {
            if (ary[i].getID()==id && ary[i]!= null) {
                System.out.println(ary[i]);
                break;
            }
        }
    }
    public void alterInfo(int id ,String num1,String num2){
        for (int i = 0; i < ary.length; i++) {
            if(ary[i] != null && ary[i].getID()==id){
                if(num1.equals("姓名")){
                    ary[i].setName(num2);
                }else if(num1.equals("性别")){
                    ary[i].setGender(num2);
                }else if(num1.equals("年龄")){
                    ary[i].setAge((Integer.parseInt(num2)));                }
                }else if(num1.equals("成绩")){
                    ary[i].setScore((Integer.parseInt(num2)));
                }
        }
    }
    public void descInfo(){
     Studentclass sum=null;
        for (int i = 0; i < ary.length; i++) {
            if(ary[i] != null ){
            for (int j = 0; j < ary.length; j++) {
                    if(ary[j] != null ){
                        if(ary[i].getScore()>ary[j].getScore()){
                            sum=ary[i];
                            ary[i]=ary[j];
                            ary[j]=sum;
                        }
                    }
                }
            }
        }
    }   

    private int getID() {
        // TODO Auto-generated method stub
        return 0;
    }

}

test.java:

package day3stu;
import java.util.Scanner;


public class test {
    public static void main(String[] args) {
            StudentManage sm = new StudentManage();
            Scanner input = new Scanner(System.in);
            int stu = 1;
            do{
            System.out.println("请输入你的操作");
            System.out.println("1:添加学生类");
            System.out.println("2:查询所有的学生");
            System.out.println("3:查询单个学生");
            System.out.println("4:修改学生信息");
            System.out.println("5:降序");
            System.out.println("0:退出程序");
            int k = input.nextInt();
            if(k==1){
                Studentclass a1 = new Studentclass(1, "张三", "男", 17, 87);
                sm.AddStudent(a1);
                Studentclass a2 = new Studentclass(2, "李四","女", 18, 91);
                sm.AddStudent(a2);
                Studentclass a3 = new Studentclass(3, "王五","女", 19, 81);
                sm.AddStudent(a3);
            }else if(k==2){
                sm.ShowAllInfo();
            }else if(k==3){
                System.out.println("请输入你要查询学生的学号:");
                int no = input.nextInt();
                sm.ShowInfoByNo(no);
            }else if(k==4){
                System.out.println("请输入你想要修改学号/姓名/性别/年龄/成绩");
                System.out.println("你要修改的学号");
                int id = input.nextInt();
                System.out.println("你要修改什么");
                String num1 =input.next();
                System.out.println("修改成什么");
                String num2 = input.next();
                sm.alterInfo(id, num1, num2);
            }else if(k==5){
                System.out.println("降序的顺序是:");
                sm.descInfo();
            }
            }while(stu!=0);
        }

}

作业文件:

作业下载

推荐阅读更多精彩内容