【JAVA】学生成绩管理系统

一、实验内容

  1. 设计Person类 (姓名,性别,生日,地址等)
  2. 设计学生Student类 (学号,专业, 所学课程,课程成绩)
    主要方法(1)添加课程,(2)添加成绩,(3)成绩查询(按课程号,按课程名等进行查询)
  3. 班级类Classes(年级,专业,班号, 学生)
    主要方法(1)添加学生,(2)添加成绩,(3)学生信息查询(按学号,按姓名等进行查询)
  4. 学院类Department (部门名称,部门简介,班级等)

二、主要实验设计思路和步骤

1.系统类图
【JAVA】学生成绩管理系统_第1张图片

2.设计思路
设计Person类,设计学生Student类,设计班级类Classes,设计学院类Department,同时设计地址Address类以及生日Birthday类,Courses课程类。
同时注意学院类继承班级类,班级类继承学生类,学生类继承人类,在人类内部构造输入地址及生日的方法,在学生类中设计添加课程的方法等等

3.步骤
首先设计人类,随后设计地址类以及生日类,之后设计人类的子类学生类,在设计班级类以及学院类,课程类可以在设计学生类是进行构造。
最终设计Main类,注意学生成绩管理系统的Main类值得反复推敲琢磨,一个舒适完美有逻辑的界面会让用户有更好的交互体验。

注意:继承关系、添加信息顺序、反馈交互…

三、实验结果

1. 主类

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("==========学生成绩管理系统==========");
        Department department = new Department();
        String choice = "1";
        while(choice.equals("0") == false) {
            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("6.添加学院信息");
            System.out.println("7.查询学院信息");
            System.out.println("0.退出程序");
            System.out.println("**********************************");
            System.out.println("请输入您的选择:");
            choice = sc.next();
            switch (choice) {
                case "1":
                    if (Classes.students == null)
                    {
                        System.out.println("请先添加学生^o^");
                        break;
                    }
                    else {
                        System.out.println("请输入需要添加课程的学生序号:");
                        int num1 = sc.nextInt();
                        Classes.students[num1].addcourse();
                        System.out.println("请问您还需要什么服务?");
                        break;
                    }
                case "2":
                    System.out.println("请输入需要查询成绩的学生序号:");
                    int num2 = sc.nextInt();
                    Classes.students[num2].searchscore();
                    System.out.println("请问您还需要什么服务?");
                    break;
                case "3":
                    if (Department.classes == null)
                    {
                        System.out.println("请先添加班级^o^");
                        break;
                    }
                    else {
                        Department.classes.addstu();
                        System.out.println("请问您还需要什么服务?");
                        break;
                    }
                case "4":
                    System.out.println("请输入查询信息学生序号:");
                    int num3 = sc.nextInt();
                    System.out.println(Classes.students[num3]);
                    System.out.println("请问您还需要什么服务?");
                    break;
                case "5":
                    System.out.println("添加班级中^o^");
                    department.addclass();
                    break;
                case "6":
                    System.out.println("请输入学院名称:");
                    department.setDepartname(sc.next());
                    System.out.println("请输入学院简介:");
                    department.setDepartintroduce(sc.next());
                    break;
                case "7":
                    System.out.println(department);
                    System.out.println("请问您还需要什么服务?");
                    break;
                case "0":
                    System.out.println("谢谢您的使用,欢迎下次光临!");
                    System.out.println("==================================");
                    break;
                default:
                    System.out.println("输入错误,请重新输入!");
                    break;
            }
        }
    }
}

2. 学院类

import java.util.*;

public class Department {
    Scanner sc = new Scanner(System.in);
    private String departname;
    private String departintroduce;
    private int max;
    public static Classes classes;

    public Department() {
    }

    public Department(String departname, String departintroduce, int max) {
        this.departname = departname;
        this.departintroduce = departintroduce;
        this.max = max;
    }

    public String getDepartname() {
        return departname;
    }

    public void setDepartname(String departname) {
        this.departname = departname;
    }

    public String getDepartintroduce() {
        return departintroduce;
    }

    public void setDepartintroduce(String departintroduce) {   // “添加学院信息”方法
        this.departintroduce = departintroduce;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public void addclass() {   // “添加班级”方法
        classes = new Classes();
        System.out.println("请输入班级所属年级:");
        classes.setGrade(sc.next());
        System.out.println("请输入班级所属专业:");
        classes.setClassmajor(sc.next());
        System.out.println("请输入班号:");
        classes.setClassnum(sc.next());
        System.out.println("请输入班级学生数:");
        classes.setMax(sc.nextInt());
    }

    @Override
    public String toString() {   // “查询学院信息”方法
        return "\t学院:" + departname + "学院\n" +
                "\t学院信息:" + departintroduce + "\n" +
                "\t学院班级数:" + max + "个\n";
    }
}

3. 班级类

import java.util.*;

public class Classes extends Student {
    Scanner sc = new Scanner(System.in);
    private String grade;
    private String classmajor;
    private String classnum;
    public static Student [] students;
    private int num = 0;
    private int max;

    public Classes() {
    }

    public Classes(String grade, String clsmajor, String classnum, int max) {
        this.grade = grade;
        this.classmajor = clsmajor;
        this.classnum = classnum;
        this.max = max;
    }

    public String getGrade() {
        return grade;
    }

    public void setGrade(String grade) {
        this.grade = grade;
    }

    public String getClassmajor() {
        return classmajor;
    }

    public void setClassmajor(String classmajor) {
        this.classmajor = classmajor;
    }

    public String getClassnum() {
        return classnum;
    }

    public void setClassnum(String classnum) {
        this.classnum = classnum;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public void addstu() {   // “添加学生”方法
        if (num == max)
            System.out.println("抱歉,该班级学生已满,无法继续添加学生!");
        else {
            if (num == 0)
            {
                students = new Student[max];
            }
            Student stu = new Student();
            System.out.println("请输入学生姓名:");
            stu.setName(sc.next());
            System.out.println("请输入学生性别:");
            stu.setSex(sc.next());
            System.out.println("请输入学生生日:");
            stu.setBirthday(sc.next(),sc.next(),sc.next());
            System.out.println("请输入学生地址(省、市、街):");
            stu.setAddress(sc.next(), sc.next(), sc.next());
            System.out.println("请输入学生学号:");
            stu.setStuid(sc.next());
            System.out.println("请输入学生专业:");
            stu.setStumajor(sc.next());
            System.out.println("请输入学生最大选课数:");
            stu.setMax(sc.nextInt());
            students[num] = stu;
            num++;
        }
    }

    @Override
    public String toString() {
        return "年级:" + grade +
                "专业:" + classmajor +
                "班号:" + classnum +
                "学生:" + Arrays.toString(students);
    }
}

4. 学生类

import java.util.*;

public class Student extends Person {
    Scanner sc = new Scanner(System.in);
    private String stuid;
    private String stumajor;
    public static Course [] courses;
    public static int [] coursescores;
    private int num = 0;
    private int max;
    private int sum = 0;

    public Student() {
    }

    public Student(String name, String sex, Birthday birthday, Address address, String stuid, String stumajor, int max) {
        super(name, sex, birthday, address);
        this.stuid = stuid;
        this.stumajor = stumajor;
        this.max = max;
    }

    public String getStuid() {
        return stuid;
    }

    public void setStuid(String stuid) {
        this.stuid = stuid;
    }

    public String getStumajor() {
        return stumajor;
    }

    public void setStumajor(String stumajor) {
        this.stumajor = stumajor;
    }

    public int getMax() {
        return max;
    }

    public void setMax(int max) {
        this.max = max;
    }

    public void addcourse() {   // “添加课程”方法
        if (num == max)
            System.out.println("抱歉,该学生课表已满,无法继续选课!");
        else {
            if (num == 0)
            {
                courses = new Course[max];
                coursescores = new int[max];
            }
            System.out.println("请输入课程名:");
            Course course = new Course(sc.next());
            courses[num] = course;
            System.out.println("请输入课程成绩:");
            int score = sc.nextInt();
            sum += score;
            coursescores[num] = score;
            num++;
        }
    }

    public void searchscore() {   // “课程成绩查询”方法
        System.out.println("\t课程:" + Arrays.toString(courses) +
                "\n\t课程成绩:" + Arrays.toString(coursescores) + "\n");
    }

    @Override
    public String toString() {   // “学生信息查询”方法
        return super.toString() +
                "\t学号:" + stuid +
                "\t专业:" + stumajor +
                "\t\t总成绩:" + sum + "\n" ;
    }
}

5. 人类

public class Person {
    private String name;
    private String sex;
    private Birthday birthday;
    private Address address;

    public Person() {
    }

    public Person (String name, String sex, Birthday birthday, Address address) {
        this.name = name;
        this.sex = sex;
        this.birthday = birthday;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Birthday getBirthday() {
        return birthday;
    }

    public void setBirthday(String year, String month, String day) {
        Birthday birthday = new Birthday(year,month,day);
        this.birthday = birthday;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(String province, String city, String street) {
        Address address = new Address(province, city, street);
        this.address = address;
    }

    @Override
    public String toString() {
        return "\t姓名:" + name +
                "\t性别:" + sex + "\n" +
                birthday +
                address ;
    }
}

6. 课程类

public class Course {
    private String coursename;

    public Course() {
    }

    public Course(String coursename) {
        this.coursename = coursename;
    }

    public String getCoursename() {
        return coursename;
    }

    public void setCoursename(String coursename) {
        this.coursename = coursename;
    }

    @Override
    public String toString() {
        return coursename;
    }
}

7. 生日类

public class Birthday {
    private String year;
    private String month;
    private String day;

    public Birthday() {
    }

    public Birthday(String year, String month, String day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public String getDay() {
        return day;
    }

    public void setDay(String day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "\t生日:" +
                month + "月" +
                day + "日\n";
    }
}

8. 地址类

public class Address {
    private String province;
    private String city;
    private String street;

    public Address() {
    }

    public Address(String province, String city, String street) {
        this.province = province;
        this.city = city;
        this.street = street;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    @Override
    public String toString() {
        return "\t地址:" +
                "【省份:" + province + "省" +
                "\t城市:" + city + "市" +
                "\t街道:" + street + "】\n";
    }
}

你可能感兴趣的:(管理系统,java,开发语言)