文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Java实现简单学生信息管理系统

2024-04-02 19:55

关注

最近在学习Java,所以写了个学生信息管理系统,话不多说,上代码。

Student.java:


package com.mumu;

public class Student {  //定义学生类
    private String name;
    private String age;
    private String id;
    private String room_num;
    private int math;
    private int english;
    private int physic;

    public Student() {//无参构造方法
    }

    public Student(String name, String age, String id, String room_num, int math, int english, int physic) {
        this.name = name;
        this.age = age;
        this.id = id;
        this.room_num = room_num;
        this.math = math;
        this.english = english;
        this.physic = physic;
    }

//Alt+ INSERT键,可自动生成构造方法
    public String getName() {
        return name;
    }

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

    public String getAge() {
        return age;
    }

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

    public String getId() {
        return id;
    }

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

    public String getRoom_num() {
        return room_num;
    }

    public void setRoom_num(String room_num) {
        this.room_num = room_num;
    }

    public int getMath() {
        return math;
    }

    public int getEnglish() {
        return english;
    }

    public int getPhysic() {
        return physic;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    public void setPhysic(int physic) {
        this.physic = physic;
    }
}

StudentManager .java:


package com.mumu;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {
    public static void main(String[] args) {

    ArrayList<Student> array=new ArrayList<>();
    menu(array);
    }
    public static void menu(ArrayList<Student> array)//菜单
    {
        while(true)
        {
            System.out.println("^^^^^^^^welcom to my System^^^^^^^^");
            System.out.println("please input your choice");
            System.out.println("1.add students' information");
            System.out.println("2.remove students' information");
            System.out.println("3.revise students' information");
            System.out.println("4.look over students' information");
            System.out.println("5.find  students' information");
            System.out.println("6.quit the system");
            Scanner sc=new Scanner(System.in);
            String choice =sc.nextLine();
            switch(choice)
            {
                case "1":
                    adding(array);
                    break;
                case "2":
                    removing(array);
                    break;
                case "3":
                    revising(array);
                    break;
                case "4":
                    look_over(array);
                    break;
                case "5":
                    serching(array);
                case "6":
                    quiting();
                    break;
                default:
                    System.out.println("error!");
                    System.exit(0);
            }
        }

    }

    public static void adding(ArrayList<Student> array)//添加学生信息
    {//录入的学生数据录入给成员变量
        System.out.println("please input student's id");
        Scanner sc=new Scanner(System.in);
        String stu_num=sc.nextLine();
        if(is_used(array,stu_num)==false)
        {
            System.out.println("please input student's name");
            String stu_name=sc.nextLine();
            System.out.println("please input student's age");
            String stu_age=sc.nextLine();
            System.out.println("please input student's room number");
            String stu_addr=sc.nextLine();
            System.out.println("do you want to add student's grade?yes/no");
            //创建学生对象
            Student st=new Student();
            st.setAge(stu_age);
            st.setId(stu_num);
            st.setName(stu_name);
            st.setRoom_num(stu_addr);
            //添加学生成绩
            String cho=sc.nextLine();
            if(cho=="yes")
            {
                System.out.println("please input student's math grade");
                int stu_math=sc.nextInt();
                System.out.println("please input student's english grade");
                int stu_english= sc.nextInt();
                System.out.println("please input student's physic grade");
                int stu_physic= sc.nextInt();
                st.setMath(stu_math);
                st.setEnglish(stu_english);
                st.setPhysic(stu_physic);
            }
            //将学生对象添加到集合中
            array.add(st);
            System.out.println("add successfully");
        }
        else
        {
            System.out.println("you are already input information of this student");
        }

    }
    public static void removing(ArrayList<Student> array)//删除学生信息
    {
    Scanner sc=new Scanner(System.in);
        System.out.println("please input student's number");
        String stu_num=sc.nextLine();
        for(int i=0;i<array.size();i++)
        {
            Student st=array.get(i);
            if(st.getId().equals(stu_num))
            {
                array.remove(i);
                break;
            }
            else
            {
                System.out.println("there is no information of that student");
            }
        }
        System.out.println("remove successfully");
    }
    public static void revising(ArrayList<Student> array)//修改学生信息
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("please input stubent's id");
        String stu_num=sc.nextLine();
        System.out.println("please input student's new name");
        String stu_name=sc.nextLine();
        System.out.println("please input student's new  id");
        String stu_id=sc.nextLine();
        System.out.println("please input student's new age");
        String stu_age=sc.nextLine();
        System.out.println("please input student's new room_number");
        String stu_add=sc.nextLine();
        System.out.println("do you want to revise student's grade?yes/no");
        //创建学生对象
        Student st1=new Student();
        st1.setRoom_num(stu_add);
        st1.setName(stu_name);
        st1.setId(stu_id);
        st1.setAge(stu_age);
        String cho= sc.nextLine();
        if(cho=="yes")
        {
            System.out.println("please input student's new math grade");
            int stu_math=sc.nextInt();
            System.out.println("please input student's new english grade");
            int stu_english=sc.nextInt();
            System.out.println("please input student's new physic grade");
            int stu_physic=sc.nextInt();
            st1.setEnglish(stu_english);
            st1.setMath(stu_math);
            st1.setPhysic(stu_physic);
        }
        for(int i=0;i< array.size();i++)
        {
            Student st2=array.get(i);
            if(st2.getId().equals(stu_num))//判断输入的学号是否在array里面
            {
                array.set(i,st1);
                break;
            }
            else
            {
                System.out.println("there is no information of that student");
            }
        }
        System.out.println("revise successfully");
    }
    public static void look_over(ArrayList<Student> array)//查看所有学生信息
    {
        if(array.size()==0)//先判断集合是否为空
        {
            System.out.println("there is no information,please input information firstly");
        }
        else
        {
            System.out.println("number\tname\tage\troom_number\tmath_grade\tenglish_grade\tphysic_grade");
            for(int i=0;i<array.size();i++)
            {
                Student st=array.get(i);
                System.out.println(st.getId()+"\t"+st.getName()+"\t"+st.getAge()+"\t"+st.getRoom_num()+"\t"
                        +st.getMath()+"\t"+st.getEnglish()+"\t"+st.getPhysic());
            }

        }

    }
    public static void quiting() //退出系统
    {
        System.exit(0);
    }

    public static boolean is_used(ArrayList<Student> array,String sid)//判断学号是否重复
    {
        boolean temp=false;
        for(int i=0;i< array.size();i++)
        {
            Student st=array.get(i);
            if(st.getId().equals(sid))
            {
                temp=true;
                break;
            }
        }
        return temp;
    }
    public static void serching(ArrayList<Student> array)//通过学号查找
  {
      System.out.println("please input id of the student you want to find");
      Scanner sc=new Scanner(System.in);
      String stu_num=sc.nextLine();
      for(int i=0;i< array.size();i++)
      {
          Student st= array.get(i);
          if(st.getId().equals(stu_num))
          {
              System.out.println(st.getId()+"\t"+st.getName()+"\t"+st.getAge()+"\t"+st.getRoom_num()+"\t"
                      +st.getMath()+"\t"+st.getEnglish()+"\t"+st.getPhysic());
          }
          else
          {
              System.out.println("there is no information of that student");
          }
      }
  }
}

代码是用IDEA写的,因为是初学者,功能相对简单,如有问题欢迎指正哦。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程网。

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯