一、前言
最近在学习JAVA,这几天跟着网上的视频学完基础知识之后,做了一个学生信息管理系统,写的比较普通,没太大亮点,希望可以给初学者一些参考经验,另外,如有不恰当的地方还请各位指正!
学生信息管理系统主要包括:显示学生信息;添加学生信息;查找学生信息;删除学生信息;修改学生信息;按照成绩排序;统计学生总数。其中录入学生的信息包括学号、姓名、性别、年龄、出生日期、学院、成绩。
二、系统主要功能
学生信息管理系统主要包括:
1、显示学生信息;
2、添加学生信息;
3、查找学生信息;
4、删除学生信息;
5、修改学生信息;
6、按照成绩排序;
7、统计学生总数;
三、系统主要功能实现
下面开始介绍代码,主要的代码处都给出了详细注释,如若有不懂的地方,请在评论区留言。
学生信息管理系统功能菜单
主界面函数代码部分,此函数主要将学生信息管理系统的功能键选择的提示信息打印出来组成了一个简易的登录界面。
实现方法具体如下:
static void show1(){System.out.println("********************************************************");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.print("请选择其功能:");}
实现效果如图所示:
显示学生信息
此函数是将初始存储的学生信息全部显示出来。
实现方法具体如下:
static void show(){ //显示学生信息System.out.println("******************************************学生信息表************************************************");System.out.println("序号\t\t\t学号\t\t\t姓名\t\t\t\t性别\t\t\t年龄\t\t\t出生日期\t\t\t学院\t\t\t\t成绩");for (int i = 0; i < students.size(); i++) {final Student student = students.get(i);System.out.println(i + 1 + "\t\t" + student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+student.getAge() + "\t\t\t" +student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());}System.out.println("**************************************************************************************************");}
实现效果如图所示:
添加学生信息
实现方法具体如下:
static void add(){//增加学生信息System.out.print("请输入您要添加学生的个数:");int s = sc.nextInt();for (int i = 0; i < s; i++) {System.out.print("请输入您要添加的学号:");String str = sc.next();int count = 0;for (final Student student : students) {if (student.getId().equals(str)) {System.out.println("已有此人!");break;}count++;}if (count == students.size()){System.out.print("姓名:");String str1 = sc.next();System.out.print("性别:");String str2 = sc.next();System.out.print("年龄:");String str3 = sc.next();System.out.print("出生日期(yyyy-mm-dd):");String str4 = sc.next();System.out.print("学院:");String str5 = sc.next();System.out.print("成绩:");int str6 = sc.nextInt();Student student = new Student(str,str1,str2,str3,str4,str5,str6);students.add(student);System.out.println("添加成功!");}}}
实现效果如图所示:
查找学生信息
此函数主要功能是查询时分为按学号查询,若查无此人则输出提示信息。
实现方法具体如下:
static void search(){//查找学生信息System.out.print("请输入您要查找的学号:");String str = sc.next();int count = 0;for (final Student student : students) {if (student.getId().equals(str)) {System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+ student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());break;}count++;}if (count == students.size()){System.out.println("查无此人!");}}
实现效果如图所示:
删除学生信息
此函数主要功能是执行删除操作,输入学号进行查找,查找到学生信息之后,对学生信息进行删除。
实现方法具体如下:
static void delete(){ //删除学生信息System.out.print("请输入您要删除的学号:");String str = sc.next();int a = students.size();int count = 0;for (int i = 0; i < students.size(); i++) {final Student student = students.get(i);if (student.getId().equals(str)){students.remove(i);System.out.println("删除成功!");break;}count++;}if (count == a){System.out.println("查无此人!");}}
实现效果如图所示:
修改学生信息
此函数的主要功能是对学生信息进行修改,当输入学号后,查询到学生信息之后,对学生信息进行修改。
实现方法具体如下:
static void modify() {//修改学生信息System.out.print("请输入您要修改的学号:");String str = sc.next();int count = 0;for (final Student student : students) {if (student.getId().equals(str)) {while (true) {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("**************************************");System.out.print("请输入您要修改的选项:");int a = sc.nextInt();if (a == 1 || a == 2 || a == 3 || a == 4 || a == 5 || a == 6) {System.out.print("修改为:");String str0 = sc.next();switch (a) {case 1 -> student.setName(str0);case 2 -> student.setSex(str0);case 3 -> student.setBirthday(str0);case 4 -> student.setAge(str0);case 5 -> student.setCollege(str0);case 6 -> student.setGrade(Integer.parseInt(str0));}System.out.println("修改成功!");break;} else {System.out.println("请输入正确的序号!");}}break;}count++;}if (count == students.size()){System.out.println("查无此人!");}}
实现效果如图所示:
按照成绩排序
此函数主要是根据学生成绩按照降序排序。
实现方法具体如下:
static void sort(){ //按照成绩排序int [][]grade = new int[students.size()][2];for (int i = 0; i < students.size(); i++) {final Student student = students.get(i);grade[i][0] = student.getGrade();grade[i][1] = i;}for (int i = 0; i < students.size(); i++) {for (int j = 1; j grade[j][0]){int a = grade[j][0];grade[j][0] = grade[j - 1][0];grade[j - 1][0] = a;int c = grade[j][1];grade[j][1] = grade[j - 1][1];grade[j - 1][1] = c;}}}for (int i = students.size() - 1; i >= 0; i--) {final Student student = students.get(grade[i][1]);System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+ student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());}}
实现效果如图所示:
统计学生总数
实现方法具体如下:
static void count(){//统计学生总数System.out.println("学生总人数为:" + students.size());}
实现效果如图所示:
完整代码:
Student.java
public class Student {private String id;//学号private String name;//姓名private String sex; //性别private String age; //年龄private String birthday;//出生日期private String college; //学院private int grade;//成绩public Student() {}public Student(String id, String name, String sex, String age, String birthday, String college, int grade) {this.id = id;this.name = name;this.sex = sex;this.age = age;this.birthday = birthday;this.college = college;this.grade = grade;}public String getId() {return id;}public void setId(String id) {this.id = id;}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 String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getBirthday() {return birthday;}public void setBirthday(String birthday) {this.birthday = birthday;}public String getCollege() {return college;}public void setCollege(String college) {this.college = college;}public int getGrade() {return grade;}public void setGrade(int grade) {this.grade = grade;}}
test.java
import java.util.ArrayList;import java.util.Scanner;public class test {static ArrayList students = new ArrayList(); //定义学生集合static Scanner sc = new Scanner(System.in);public static void main(String[] args) {show0();while (true) {show1();int a = sc.nextInt();if (a == 0){break;}switch (a) {case 1 -> show();case 2 -> add();case 3 -> delete();case 4 -> modify();case 5 -> search();case 6 -> sort();case 7 -> count();default -> System.out.println("请输入正确序号!");}}}static void show0(){//录入初始学生信息Student student = new Student("54213460501","许雅静","男","45","2002-01-24","软件学院",98);Student student1 = new Student("54213460502","段清堂","女","25","2002-07-24","通信学院",78);Student student2 = new Student("54213460503","曲双红","男","36","2002-04-14","外语学院",69);Student student3 = new Student("54213460504","伍四六","女","29","2001-09-21","国教学院",97);Student student4 = new Student("54213460505","葛瑞格","男","45","2002-01-24","艺设学院",82);students.add(student);students.add(student1);students.add(student2);students.add(student3);students.add(student4);}static void show1(){System.out.println("********************************************************");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.print("请选择其功能:");}static void show(){ //显示学生信息System.out.println("******************************************学生信息表************************************************");System.out.println("序号\t\t\t学号\t\t\t姓名\t\t\t\t性别\t\t\t年龄\t\t\t出生日期\t\t\t学院\t\t\t\t成绩");for (int i = 0; i < students.size(); i++) {final Student student = students.get(i);System.out.println(i + 1 + "\t\t" + student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+student.getAge() + "\t\t\t" +student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());}System.out.println("**************************************************************************************************");}static void add(){//增加学生信息System.out.print("请输入您要添加学生的个数:");int s = sc.nextInt();for (int i = 0; i < s; i++) {System.out.print("请输入您要添加的学号:");String str = sc.next();int count = 0;for (final Student student : students) {if (student.getId().equals(str)) {System.out.println("已有此人!");break;}count++;}if (count == students.size()){System.out.print("姓名:");String str1 = sc.next();System.out.print("性别:");String str2 = sc.next();System.out.print("年龄:");String str3 = sc.next();System.out.print("出生日期(yyyy-mm-dd):");String str4 = sc.next();System.out.print("学院:");String str5 = sc.next();System.out.print("成绩:");int str6 = sc.nextInt();Student student = new Student(str,str1,str2,str3,str4,str5,str6);students.add(student);System.out.println("添加成功!");}}}static void delete(){ //删除学生信息System.out.print("请输入您要删除的学号:");String str = sc.next();int a = students.size();int count = 0;for (int i = 0; i student.setName(str0);case 2 -> student.setSex(str0);case 3 -> student.setBirthday(str0);case 4 -> student.setAge(str0);case 5 -> student.setCollege(str0);case 6 -> student.setGrade(Integer.parseInt(str0));}System.out.println("修改成功!");break;} else {System.out.println("请输入正确的序号!");}}break;}count++;}if (count == students.size()){System.out.println("查无此人!");}}static void search(){//查找学生信息System.out.print("请输入您要查找的学号:");String str = sc.next();int count = 0;for (final Student student : students) {if (student.getId().equals(str)) {System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+ student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());break;}count++;}if (count == students.size()){System.out.println("查无此人!");}}static void sort(){ //按照成绩排序int [][]grade = new int[students.size()][2];for (int i = 0; i < students.size(); i++) {final Student student = students.get(i);grade[i][0] = student.getGrade();grade[i][1] = i;}for (int i = 0; i < students.size(); i++) {for (int j = 1; j grade[j][0]){int a = grade[j][0];grade[j][0] = grade[j - 1][0];grade[j - 1][0] = a;int c = grade[j][1];grade[j][1] = grade[j - 1][1];grade[j - 1][1] = c;}}}for (int i = students.size() - 1; i >= 0; i--) {final Student student = students.get(grade[i][1]);System.out.println(student.getId() + "\t\t" + student.getName() + "\t\t\t" + student.getSex() + "\t\t\t"+ student.getAge() + "\t\t\t" + student.getBirthday() + "\t\t" + student.getCollege() + "\t\t\t" + student.getGrade());}}static void count(){//统计学生总数System.out.println("学生总人数为:" + students.size());}}
四、总结
以上就是我实现学生信息管理系统的方案,本文仅仅介绍了实现方案及制作流程,仅供参考,若有问题请帮忙留言指出,欢迎交流学习。