Java的学生信息管理系统

@Java

学生成绩管理系统

在这里插入图片描述

//Student类

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.List;
import java.util.Random;

class Student {
    private String stuNo;/*学号*/private String name;/*姓名*/
    private Integer score1;private Integer score2;
    private Integer score3;private Integer score;
    private double ver;//score1:语文;score2:数学;score3:英语;score:总成绩;ver:平均成绩。//
    private String password;/*密码*/
    public Student() {}
    public Student(String stuNo, String name, Integer score1, Integer score2,Integer score3, Integer score, double ver, String password) {
        this.stuNo = stuNo;this.name = name;
        this.score1 = score1;this.score2 = score2;this.score3 = score3;       
        this.score = score; this.password = password;this.ver=ver;
    }
    public String getStuNo() {
        return stuNo;
    }
    public void setStuNo(String stuNo) {
        this.stuNo = stuNo;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getscore1() {
        return score1;
    }
    public void setscore1(Integer score1) {
        this.score1 = score1;
    }//11111
    public Integer getscore2() {
        return score2;
    }
    public void setscore2(Integer s) {
        this.score2 = s;
    }//22222
    public Integer getscore3() {
        return score3;
    }
    public void setscore3(Integer sc) {
        this.score3 = sc;
    }//33333
    public double getver() {
        return ver;
    }
    public void setver(double sc) {
        this.ver = sc;
    }//ver
    public Integer getScore() {
        return score;
    }
    public void setScore(Integer score) {
        this.score = score;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String toString() {
        return stuNo+"|  "+name+"|  "+score1+"|  "+score2+"|  "+score3+"| "+score+"| "+ver+"| "+password+"|";
    }
}

//StudentService

interface StudentService {

   /**
    * 添加学生信息
    * @param all 学生列表
    */
   void addStudentInfo(List<Student> all,Student student);
   /**
    *  修改学生信息
    * @param all 所有学生的列表
    * @param student  需要修改的学生
    * @return  当前的学生列表
    */
   List<Student> updateStudentInfo(List<Student> all , Student student);

   /**
    *
    * 删除学生信息
    * @param all  所有学生的列表
    * @param name 需要删除的学生姓名
    * @return  当前的学生列表
    */
   List<Student> deleteStudentInfo(List<Student> all , String name);

   /**
    * 打印学生列表
    * @param all 当前学生列表
    * @return 返回打印结果
    */
   void printStudentList(List<Student> all);

   /**
    * 打印个人信息
    * @param student 当前学生
    */
   void printMine(Student student);

   /**
    * 初始化学生信息
    * @param students 学生列表
    */
   void initStudentList(List<Student> students);

}
 
class StudentServiceImpl implements StudentService {
    @Override
    public void addStudentInfo(List<Student> all,Student student) {
        all.add(student);
        System.out.println("学生信息已添加");
    }
 
    @Override
    public List<Student> updateStudentInfo(List<Student> all, Student student) {
        for (Student student1 : all) {
            if (student1.getStuNo().equals(student.getStuNo())){
                student1.setName(student.getName());
                student1.setscore1(student.getscore1());
                student1.setscore2(student.getscore2());
                student1.setscore3(student.getscore3());
                
                student1.setScore(student.getScore());
                student1.setver(student.getver());
                student1.setPassword(student.getPassword());
                System.out.println("==============个人信息已更新=============");
                printMine(student1);
                break;
            }
        }
        return all;
    }
 
    
    public List<Student> deleteStudentInfo(List<Student> all, String name) {
        int size = all.size();
        for (Student student1 : all) {
            if (student1.getName().equals(name)){
                System.out.println("-------消息通知----------");
                System.out.println("|   成功删除"+name+"     |");
                System.out.println("------------------------");
                all.remove(student1);
                break;
            }
        }
        if (all.size()==size){
            System.out.println("-------消息通知----------");
            System.out.println("|     不存在该学生        |");
            System.out.println("------------------------");
        }
        return all;
    }
 
    @Override
    public void printStudentList(List<Student> all) {
        System.out.println("================学生信息================");
        System.out.println("学号| 姓名| 语文| 数学| 英语| 总分| 平均| 密码|");
        for (Student student : all) {
            System.out.println(student.toString());
        }
        System.out.println("--------------------------------------");
    }
 
    @Override
    public void printMine(Student student) {
        System.out.println("============我的个人信息=============");
        System.out.println("学号--->"+student.getStuNo());
        System.out.println("姓名--->"+student.getName());
        System.out.println("语文--->"+student.getscore1());
        System.out.println("数学--->"+student.getscore2());
        System.out.println("英语--->"+student.getscore3());
        System.out.println("成绩--->"+student.getScore());
        System.out.println("平均--->"+student.getver());
        System.out.println("密码--->"+student.getPassword());
        System.out.println("-----------------------------------");
    }
 
    @Override
    public void initStudentList(List<Student> students) {
        Random random = new Random();
        for (int i = 1; i <= 10; i++) { 
        	int a=random.nextInt(100);
        	int b=random.nextInt(100);
        	int c=random.nextInt(100);
            Student student = new Student("No."+i,"学生"+i,a,b,c,a+b+c,(a+b+c)/3,"123");
            students.add(student);
        }
    }
}
/**
 * 本模块代码来自于@author pengyangyan
 */

//主函数demo

public class demo {
 
    /*学生列表*/
    private static List<Student> students = new ArrayList<Student>();
    /* 输入 */
    private static Scanner scanner = new Scanner(System.in);
    /* 是否登录的标志*/
    private static boolean isLogin = false;
    /* 当前登录的学生信息*/
    private static Student current = new Student();
 
    private static StudentServiceImpl studentService = new StudentServiceImpl();
 
    public static void main(String[] args) throws InterruptedException {
        System.out.println("正在初始化....");
        Thread.sleep(3000);
        studentService.initStudentList(students);
        int choose = Integer.parseInt(Menu());
        while (choose<11){
            switch (choose) {
                case 1:
                    login();
                    break;
                case 2:
                    regester();
                    break;
                case 3:
                    studentService.printStudentList(students);
                    break;
                case 4:
                    if (isLogin){
                        System.out.println("====>个人资料");
                        studentService.printMine(current);
                    }else {
                        System.out.println("您尚未登录!");
                    }
                    break;
                case 5: {
                    if (isLogin){
                        System.out.println("输入需要删除的学生姓名");
                        String name = scanner.next();
                        studentService.deleteStudentInfo(students, name);
                    }else {
                        System.out.println("请先登录!");
                    }
                }
                break;
                case 6:
                    update();
                    break;
                case 7:
                    sortByScore();
                    break;
                case 8:
                    sortByver();
                    break;
                default:
                	 System.out.println("已退出");
                    break;
          
            }
            choose = Integer.parseInt(Menu());
        }
 
    }
 
    private static String Menu() {
        System.out.println("=============学生管理系统============");
        System.out.println("1.登录 2.注册");
        System.out.println("3.查看学生列表");
        System.out.println("4.查看个人信息");
        System.out.println("5.删除学生信息");
        System.out.println("6.更新学生信息");
        System.out.println("7.根据总成绩排名");
        System.out.println("8.根据平均分排名");
        System.out.println("*0键退出*");
        System.out.println("==================================");
        System.out.print("输入你需要选择的选项编号:");
        return scanner.next();
    }
 
    /*登录系统*/
    private static void login(){
        System.out.print("输入学号:");
        String username = scanner.next();
        System.out.print("输入密码:");
        String password = scanner.next();
        for (Student student : students) {
            if (student.getStuNo().equals(username) && student.getPassword().equals(password)){
                isLogin = true;
                current.setStuNo(student.getStuNo());
                current.setName(student.getName());
                current.setscore1(student.getscore1());
                current.setscore2(student.getscore2());
                current.setscore3(student.getscore3());
                current.setScore(student.getScore());
                current.setver(student.getver());
                current.setPassword(student.getPassword());
                break;
            }
        }
        if (isLogin){
            System.out.println("登录成功");
        }else {
            System.out.println("学号或者密码错误");
        }
        
        
    }
 
    /*注册/添加学生*/
    private static void regester(){
        System.out.println("输入学生基本信息=====>");
        System.out.print("学号:");
        String stuNo = scanner.next();
        for (Student student : students) {
            if (student.getStuNo().equals(stuNo)){
                System.out.println("已存在改学号学生,请重新输入");
                System.out.print("学号:");
                stuNo = scanner.next();
            }
        }
        System.out.print("姓名:");
        String name = scanner.next();
        System.out.print("语文:");
        Integer score1 = scanner.nextInt();
        System.out.print("数学:");
        Integer score2 = scanner.nextInt();
        System.out.print("英语:");
        Integer score3 = scanner.nextInt();
        System.out.print("成绩:");
        Integer score = scanner.nextInt();
        System.out.print("平均:");
        Integer ver = scanner.nextInt();
        System.out.print("密码:");
        String password = scanner.next();
        Student student = new Student(stuNo,name,score1,score2,score3,score,ver,password);
        studentService.addStudentInfo(students,student);
 
    }
 
    /*更新学生信息*/
    private static void update(){
        if (isLogin){
            studentService.printStudentList(students);
            System.out.print("输入需要更新的学号:");
            String stuNo = scanner.next();
            System.out.print("姓名:");
            String name = scanner.next();
            System.out.print("语文:");
            Integer score1 = scanner.nextInt();
            System.out.print("数学:");
            Integer score2 = scanner.nextInt();
            System.out.print("英语:");
            Integer score3 = scanner.nextInt();
            System.out.print("成绩:");
            Integer score = scanner.nextInt();
            System.out.print("平均:");
            Integer ver = scanner.nextInt();
            System.out.print("密码:");
            String password = scanner.next();
            Student student = new Student(stuNo,name,score1,score2,score3,score,ver,password);
            studentService.updateStudentInfo(students,student);
        }else {
            System.out.println("请先登录!");
        }
 
    }
 
    /*按总成绩排名*/
    private static void sortByScore(){
        List<Student> list = students;
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = i+1; j<list.size();j++ ){
                if (list.get(i).getScore()>list.get(j).getScore()){
                    swap(list.get(i),list.get(j));
                }
            }
        }
        studentService.printStudentList(list);
    }
 
    /*按平均排名*/
    private static void sortByver(){
        List<Student> list = students;
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = i+1; j<list.size();j++ ){
                if (list.get(i).getver()>list.get(j).getver()){
                    swap(list.get(i),list.get(j));
                }
            }
        }
        studentService.printStudentList(list);
    }
    private static void swap(Student m,Student n){
        Student student = new Student(m.getStuNo(),m.getName(),m.getscore1(),m.getscore2(),m.getscore3(),m.getScore(),m.getver(),m.getPassword());
        m.setStuNo(n.getStuNo());
        m.setName(n.getName());
        m.setscore1(n.getscore1());m.setscore2(n.getscore2());m.setscore3(n.getscore3());
        m.setScore(n.getScore());m.setver(n.getver());
        m.setPassword(n.getPassword());
        n.setStuNo(student.getStuNo());
        n.setName(student.getName());
        n.setscore1(student.getscore1());n.setscore2(student.getscore2());n.setscore3(student.getscore3());
        n.setScore(student.getScore());
        n.setPassword(student.getPassword());
    }
 
}

这次大作业让我把之前所学的Java知识整合了一下,综合运用之前的知识进行系统编程。我的代码中有不少也是借鉴了一些大佬的代码,然后自己改的,大佬的代码对我的帮助非常大,侵删。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

credit1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值