添砖Java之路(其六)——通过集合制作的学生信息管理系统

目录

前言:

源码:


前言:

我对于集合的理解,感觉就类似于顺序表这样的数据结构,然后他存储的数据不能是基本类型,如果要用也只能用对应基本数据的包装类。

对于集合有很多方法,我的建议就是去api里面文档查看就行,没必要可以去背。

源码:

哈哈哈,这个系统太经典了,拿来练习语法再合适不过了~

实体类:

java 复制代码
public class StudentInfor {
    private String id;
    private String name;
    private int age;
    private String sex;
    private int MathScore;
    private int ChineseSocre;
    private  int EnglishScore;

    private   int arrSocre;



    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public StudentInfor() {

    }

    public StudentInfor(String id, String name, int age, String sex, int mathScore, int chineseSocre, int englishScore) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.sex = sex;
        MathScore = mathScore;
        ChineseSocre = chineseSocre;
        EnglishScore = englishScore;
        arrSocre=mathScore+chineseSocre+englishScore;
    }

    public int getArrSocre() {
        return arrSocre;
    }

    public void setArrSocre() {
            arrSocre=MathScore+EnglishScore+ChineseSocre;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

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

    public int getMathScore() {
        return MathScore;
    }

    public void setMathScore(int mathScore) {
        MathScore = mathScore;
    }

    public int getChineseSocre() {
        return ChineseSocre;
    }

    public void setChineseSocre(int chineseSocre) {
        ChineseSocre = chineseSocre;
    }

    public int getEnglishScore() {
        return EnglishScore;
    }

    public void setEnglishScore(int englishScore) {
        EnglishScore = englishScore;
    }
}

方法类:

java 复制代码
import java.util.ArrayList;
import java.util.Scanner;

public class System_Z {

    private static void SetInfor(ArrayList<StudentInfor> list)
    {
        StudentInfor student  = new StudentInfor();

        Scanner sc=new Scanner(System.in);
        System.out.println("请输入姓名->");
        student.setName(sc.next());
        System.out.println("请输入学号->");
        String id=sc.next();
        for (int i = 0; i < list.size(); i++) {
            while (id.equals(list.get(i).getId())) {
                System.out.println("已存在该学号!");
                System.out.println("请重新输入");
                id = sc.next();
            }
        }
        student.setId(id);
        System.out.println("请输入年龄->");
        student.setAge(sc.nextInt());
        System.out.println("请输入性别->");
        student.setSex(sc.next());
        System.out.println("请输入语文成绩");
        student.setChineseSocre(sc.nextInt());
        System.out.println("请输入数学成绩");
        student.setMathScore(sc.nextInt());
        System.out.println("请输入英语成绩");
        student.setEnglishScore(sc.nextInt());
        student.setArrSocre();
        list.add(student);
    }

    private  static  void PrintAllStudent(ArrayList<StudentInfor>list)
    {

            System.out.println("姓名   id           年龄   性别   语文   数学   英语   总分");
        for (int i = 0; i < list.size(); i++) {
/*            System.out.println(list.get(i).getName()+"   "+list.get(i).getId()+"   "+list.get(i).getAge()+"   "+list.get(i).getSex()
            +"    "+list.get(i).getChineseSocre()+"\t"+list.get(i).getMathScore()+"   "+list.get(i).getEnglishScore()+"  "+list.get(i).getArrSocre());*/
            System.out.printf("%-5s%-13s%-6d%-6s%-6d%-6d%-6d%-6d\n",
                    list.get(i).getName(),list.get(i).getId(),list.get(i).getAge(),list.get(i).getSex()
                    ,list.get(i).getChineseSocre(),list.get(i).getMathScore(),list.get(i).getEnglishScore()
                    ,list.get(i).getArrSocre());

        }
    }
    private  static void  Print()
    {
        System.out.println("1.录入学生信息");
        System.out.println("2.输入id查看学生信息");
        System.out.println("3.输入学生姓名查看学生信息");
        System.out.println("4.输入学号修改学生信息");
        System.out.println("5.打印全部学生信息");
        System.out.println("6.输入学号删除学生信息");
        System.out.println("0.退出");
    }

    private static void  FindByName(ArrayList<StudentInfor> list )
    {
        System.out.println("请输入要查的学生姓名");
        Scanner sc=new Scanner(System.in);
        String name=sc.next();
        int n=0;
        for (int i = 0; i < list.size(); i++) {
            if(name.equals(list.get(i).getName()))
            {
                n=1;
                System.out.println("学生姓名:"+list.get(i).getName());
                System.out.println("学生id:"+list.get(i).getId());
                System.out.println("学生年龄:"+list.get(i).getAge());
                System.out.println("学生性别:"+list.get(i).getSex());
                System.out.println("语文成绩:"+list.get(i).getChineseSocre());
                System.out.println("数学成绩:"+list.get(i).getMathScore());
                System.out.println("英语成绩:"+list.get(i).getEnglishScore());
                System.out.println("总成绩:"+list.get(i).getArrSocre());
                System.out.println();
            }
        }
    if(n==0)
    {
        System.out.println("没找到喵");
        System.out.println();
    }
    }

    private static void  FindByID(ArrayList<StudentInfor> list )
    {
        System.out.println("请输入要查的学号");
        Scanner sc=new Scanner(System.in);
        String id=sc.next();
        for (int i = 0; i < list.size(); i++) {
            if(id.equals(list.get(i).getId()))
            {
                System.out.println("学生姓名:"+list.get(i).getName());
                System.out.println("学生id:"+list.get(i).getId());
                System.out.println("学生年龄:"+list.get(i).getAge());
                System.out.println("学生性别:"+list.get(i).getSex());
                System.out.println("语文成绩:"+list.get(i).getChineseSocre());
                System.out.println("数学成绩:"+list.get(i).getMathScore());
                System.out.println("英语成绩:"+list.get(i).getEnglishScore());
                System.out.println("总成绩:"+list.get(i).getArrSocre());
                System.out.println();
                return ;
            }
        }
        System.out.println("没找到喵");
        System.out.println();
    }

    private static  void RemakeByname(ArrayList<StudentInfor>list )
    {
        System.out.println("请输入要修改学生的学号");
        Scanner sc=new Scanner(System.in);
        String id=sc.next();
        for (int i = 0; i < list.size(); i++) {
            if(id.equals(list.get(i).getId()))
            {

                System.out.println("请输入姓名->");
                list.get(i).setName(sc.next());
                System.out.println("请输入学号->");
                list.get(i).setName(sc.next());
                System.out.println("请输入年龄->");
                list.get(i).setAge(sc.nextInt());
                System.out.println("请输入性别->");
                list.get(i).setSex(sc.next());
                System.out.println("请输入语文成绩");
                list.get(i).setChineseSocre(sc.nextInt());
                System.out.println("请输入数学成绩");
                list.get(i).setMathScore(sc.nextInt());
                System.out.println("请输入英语成绩");
                list.get(i).setEnglishScore(sc.nextInt());
                list.get(i).setArrSocre();
                return ;
            }
        }
    }

    private  static void DeleteByid(ArrayList<StudentInfor>list)
    {
        System.out.println("请输入要查的学号");
        Scanner sc=new Scanner(System.in);
        String id=sc.next();
        for (int i = 0; i < list.size(); i++) {
            if(id.equals(list.get(i).getId()))
            {
                list.remove(i);
                System.out.println("删除成功!");
                return ;
            }
        }
        System.out.println("没有查找到该学生信息喵~");
    }

    private static void main(String[] args) {
        ArrayList<StudentInfor> list=new ArrayList<>();
        StudentInfor s1=new StudentInfor("2023211661","牢大",24,"男",59,89,100);
        StudentInfor s2=new StudentInfor("2023211662","蔡徐坤",25,"男",88,81,66);
        list.add(s1);
        list.add(s2);
        System.out.println("-------欢迎使用学生信息管理系统------");
        Scanner sc=new Scanner(System.in);
        int choice=100;
        while(choice!=0)
        {
            Print();
           choice = sc.nextInt();
            switch(choice)
            {
                case 1:
                    SetInfor(list);
                    break;
                case 2:
                    FindByID(list);
                    break;
                case 3:
                    FindByName(list);
                    break;
                case 4:RemakeByname(list);
                    break;
                case 5:
                    PrintAllStudent(list);
                    System.out.println();
                    break;
                case 6:
                    DeleteByid(list);
                    break;
                case 0:
                    System.out.println("欢迎下次使用喵~");
                    break;
                default:
                    System.out.println("选择错误请重新选择");
                    System.out.println();
                    break;
            }
        }
    }

}
相关推荐
百流24 分钟前
scala文件编译相关理解
开发语言·学习·scala
蘑菇丁26 分钟前
ansible批量生产kerberos票据,并批量分发到所有其他主机脚本
java·ide·eclipse
呼啦啦啦啦啦啦啦啦1 小时前
【Redis】持久化机制
java·redis·mybatis
Evand J2 小时前
matlab绘图——彩色螺旋图
开发语言·matlab·信息可视化
我想学LINUX2 小时前
【2024年华为OD机试】 (A卷,100分)- 微服务的集成测试(JavaScript&Java & Python&C/C++)
java·c语言·javascript·python·华为od·微服务·集成测试
深度混淆2 小时前
C#,入门教程(04)——Visual Studio 2022 数据编程实例:随机数与组合
开发语言·c#
雁于飞2 小时前
c语言贪吃蛇(极简版,基本能玩)
c语言·开发语言·笔记·学习·其他·课程设计·大作业
wenxin-3 小时前
NS3网络模拟器中如何利用Gnuplot工具像MATLAB一样绘制各类图形?
开发语言·matlab·画图·ns3·lr-wpan
数据小爬虫@5 小时前
深入解析:使用 Python 爬虫获取苏宁商品详情
开发语言·爬虫·python