计算机科学与技术专业成绩管理系统

计算机科学与技术专业学生成绩管理系统计科专业学生成绩管理系统学生数据由学号、姓名、班级、三门课(数学、英语、计算机)的成绩和平均成绩构成。实现功能包括:(1)添加学生的记录(2)查询学生(分别按学号和姓名)(3)对学生数据排序(分别按平均成绩和计算机成绩的降序)(4)删除学生记录(5)修改学生记录(6)班级成绩分析(各科平均成绩、最高分、最低分、及格率)(7)输出学生信息表(7)输出学生信息表

import java.util.*;

class Student {
    String id;
    String name;
    String className;
    double mathScore;
    double englishScore;
    double computerScore;
    double averageScore;

    public Student(String id, String name, String className, double mathScore, double englishScore, double computerScore) {
        this.id = id;
        this.name = name;
        this.className = className;
        this.mathScore = mathScore;
        this.englishScore = englishScore;
        this.computerScore = computerScore;
        this.averageScore = (mathScore + englishScore + computerScore) / 3;
    }
}

public class StudentManagementSystem {
    List<Student> students = new ArrayList<>();

    // 添加学生的记录
    public void addStudent(String id, String name, String className, double mathScore, double englishScore, double computerScore) {
        Student student = new Student(id, name, className, mathScore, englishScore, computerScore);
        students.add(student);
    }

    // 按学号查询学生
    public Student findStudentById(String id) {
        for (Student student : students) {
            if (student.id.equals(id)) {
                return student;
            }
        }
        return null;
    }

    // 按姓名查询学生
    public List<Student> findStudentsByName(String name) {
        List<Student> foundStudents = new ArrayList<>();
        for (Student student : students) {
            if (student.name.equals(name)) {
                foundStudents.add(student);
            }
        }
        return foundStudents;
    }

    // 对学生数据排序(按平均成绩降序)
    public void sortStudentsByAverageScore() {
        Collections.sort(students, (a, b) -> Double.compare(b.averageScore, a.averageScore));
    }

    // 对学生数据排序(按计算机成绩降序)
    public void sortStudentsByComputerScore() {
        Collections.sort(students, (a, b) -> Double.compare(b.computerScore, a.computerScore));
    }

    // 删除学生记录
    public void deleteStudent(String id) {
        students.removeIf(student -> student.id.equals(id));
    }

    // 修改学生记录
    public void updateStudent(String id, String name, String className, double mathScore, double englishScore, double computerScore) {
        for (Student student : students) {
            if (student.id.equals(id)) {
                student.name = name;
                student.className = className;
                student.mathScore = mathScore;
                student.englishScore = englishScore;
                student.computerScore = computerScore;
                student.averageScore = (mathScore + englishScore + computerScore) / 3;
                break;
            }
        }
    }

    // 班级成绩分析(各科平均成绩、最高分、最低分、及格率)
    public void analyzeClassScore() {
        double totalMathScore = 0;
        double totalEnglishScore = 0;
        double totalComputerScore = 0;
        double highestMathScore = Double.MIN_VALUE;
        double lowestMathScore = Double.MAX_VALUE;
        double highestEnglishScore = Double.MIN_VALUE;
        double lowestEnglishScore = Double.MAX_VALUE;
        double highestComputerScore = Double.MIN_VALUE;
        double lowestComputerScore = Double.MAX_VALUE;
        int passCount = 0;

        for (Student student : students) {
            totalMathScore += student.mathScore;
            totalEnglishScore += student.englishScore;
            totalComputerScore += student.computerScore;
            highestMathScore = Math.max(highestMathScore, student.mathScore);
            lowestMathScore = Math.min(lowestMathScore, student.mathScore);
            highestEnglishScore = Math.max(highestEnglishScore, student.englishScore);
            lowestEnglishScore = Math.min(lowestEnglishScore, student.englishScore);
            highestComputerScore = Math.max(highestComputerScore, student.computerScore);
            lowestComputerScore = Math.min(lowestComputerScore, student.computerScore);
            if (student.mathScore >= 60 && student.englishScore >= 60 && student.computerScore >= 60) {
                passCount++;
            }
        }

        double averageMathScore = totalMathScore / students.size();
        double averageEnglishScore = totalEnglishScore / students.size();
        double averageComputerScore = totalComputerScore / students.size();
        double passRate = (double) passCount / students.size() * 100;

        System.out.println("各科平均成绩:");
        System.out.println("数学:" + averageMathScore);
        System.out.println("英语:" + averageEnglishScore);
        System.out.println("计算机:" + averageComputerScore);
        System.out.println("最高分:");
        System.out.println("数学:" + highestMathScore);
        System.out.println("英语:" + highestEnglishScore);
        System.out.println("计算机:" + highestComputerScore);
        System.out.println("最低分:");
        System.out.println("数学:" + lowestMathScore);
        System.out.println("英语:" + lowestEnglishScore);
        System.out.println("计算机:" + lowestComputerScore);
        System.out.println("及格率:" + passRate + "%");
    }

    // 输出学生信息表
    public void printStudentInfoTable() {
        System.out.println("学号\t姓名\t班级\t数学成绩\t英语成绩\t计算机成绩\t平均成绩");
        for (Student student : students) {
            System.out.println(student.id + "\t" + student.name + "\t" + student.className + "\t" + student.mathScore + "\t" + student.englishScore + "\t" + student.computerScore + "\t" + student.averageScore);
        }
    }
}

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值