java学生成绩管理系统
管理系统要求
编写学生系统的java程序
1.能正常显示欢迎信息、退出系统
2.每次执行各种操作成功都能显示欢迎语并且让用户选择操作。当用户选择错误数字执行时要有提示信息。
3.可以添加学生信息
4.要根据专业进行添加,相同专业学生信息保存到list中,根据专业保存到hashmap。
如果输入专业不是1,2值时,提示用户信息错误
5.可以根据学号删除学生信息
6.没有学生信息时,不能删除。
7.输入学号,学号不正确时,不能删除。
8.可以根据学号查找学生信息
没有学生信息时,不能查找,有学生时,显示查找学生信息
9.能正常显示所有学生信息
10.没有学生信息时,显示无学生信息
11. 其中一专业无学生信息时,要显示相关专业未曾加学生,不能显示记录
12.可以正常显示所有专业学生
13. 显示每个专业的人数及总人数。
14.修改学生信息
具体要求
百度云链接:java学生管理系统要求
提取码:提取码:c2e7
运行效果如下
1.能正常显示欢迎信息、退出系统
每次执行各种操作成功都能显示欢迎语并且让用户选择操作。
当用户选择错误数字执行时要有提示信息
2.可以添加学生信息
要根据专业进行添加,相同专业学生信息保存到list中,根据专业保存。
如果输入专业不是1,2值时,提示用户信息错误
学号重复,提醒并重新输入
3.可以根据学号删除学生信息
没有学生信息不能删除
学号错误不能删除
成功删除
4根据学号查找学生信息
没有学生信息时,不能查找
有学生时,显示查找学生信息
5显示所有学生信息
没有学生信息时,显示无学生信息
其中一专业无学生信息时,要显示相关专业未曾加学生,不能显示记录
可以正常显示所有专业学生
显示每个专业的人数及总人数
6更改学生信息
无信息,不能更改
有信息更改
原信息 更改 现信息
代码如下
student类
在这里插入代码片
package Study;
import com.sun.tools.attach.VirtualMachineDescriptor;
/*
学生类
Alt + Insert 根据自己的需要进行选择
*/
public class Student {
//专业
private String profession;
//学号
private String sid;
//姓名
private String name;
//Chinese
private double Chinese;
//Math
private double Math;
//English
private double English;
//software
private double Software;
//aver & total
private double total;
private double aver;
public Student() {
}
public Student(String profession,String sid, String name, double Math, double Chinese,double English, double Software, double aver,double total) {
this.profession = profession;
this.sid = sid;
this.name = name;
this.Math = Math;
this.Chinese = Chinese;
this.English = English;
this.Software = Software;
this.aver = aver;
this.total = total;
}
public String getprofession() {
return profession;
}
public void setprofession(String profession) {
this.profession = profession;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMath() {return Math;}
public void setMath(double Math) {
this.Math = Math;
}
public double getChinese() {return Chinese;}
public void setChinese(double Chinese) {
this.Chinese = Chinese;
}
public double getEnglish() {return English;}
public void setEnglish(double English) {
this.English = English;
}
public double getSoftware() {return Software;}
public void setSoftware(double Software) {
this.Software = Software;
}
public double gettotal() {return total;}
public void settotal(double total) {
this.total = total;
}
public double getaver() {return aver;}
public void setaver(double aver) {
this.aver = aver;
}
}
主函数
在这里插入代码片
package Study;
import com.sun.tools.attach.VirtualMachineDescriptor;
import jdk.swing.interop.SwingInterOpUtils;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Scanner;
/*
学生管理系统
*/
public class StudentManager {
/*
1:用输出语句完成主界面的编写
2:用Scanner实现键盘录入数据
3:用switch语句完成操作的选择
4:用循环完成再次回到主界面
*/
public static void main(String[] args) {
//创建一个集合对象用于储存学生数据
ArrayList<Student> array = new ArrayList<>();
//用循环完成再次回到主界面
while (true) {
//用输出语句完成主界面的编写
System.out.println("--------欢迎来到学生管理系统--------");
System.out.println("0 添加学生信息");
System.out.println("1 将学生信息删除");
System.out.println("2 根据学号查询学生");
System.out.println("3 查看所有学生");
System.out.println("4 修改学生信息");
System.out.println("5 退出");
System.out.println("请输入您的选择:");
//用Scanner实现键盘录入数据
Scanner sc = new Scanner(System.in);
String line = sc.nextLine();
//用switch语句完成操作的选择
switch (line) {
case "0":
// System.out.println("添加学生");
addStudent(array);
break;
case "1":
// System.out.println("删除学生");
deleteStudent(array);
break;
case "2":
// System.out.println("根据学号查询学生");
lookforStudent(array);
break;
case "4":
// System.out.println("修改学生");
updateStudent(array);
break;
case "3":
// System.out.println("查看所有学生");
findAllStudent(array);
break;
case "5":
System.out.println("谢谢使用");
// break;
System.exit(0); //JVM(java虚拟机)退出
default:
System.out.println("输入错误,重新输入(输入0-5的数字)");
}
}
}
//定义一个方法,用于添加学生信息
public static void addStudent(ArrayList<Student> array) {
//创建学生对象,把键盘录入的数据赋值给学生对象成员变量
Student s = new Student();
//键盘录入学生对象所需要的数据,显示提示信息,提示要输入何种信息
Scanner sc = new Scanner(System.in);
String profession;
System.out.println("请输入学生专业:1英语,2软件");
profession = sc.nextLine();
while(true) {
if (profession.equals("1")) {
break;
} else if (profession.equals("2")) {
break;
} else {
System.out.println("输入错误,请重新输入专业:1英语,2软件");
profession = sc.nextLine();
}
}
//int profession=Integer.parseInt(profession1);
//为了能使得sid能在while循环外面被访问到,我们就把他定义到了循环外面
String sid;
while (true) {
System.out.println("请输入学生学号:");
sid = sc.nextLine();
boolean flag = isUsed(array, sid);
if (flag) {
System.out.println("你输入的学号已经被使用,请重新输入");
} else {
break;
}
}
System.out.println("请输入学生姓名:");
String name = sc.nextLine();
System.out.println("请输入学生语文成绩:");
String Chinese1 =sc.nextLine();
double Chinese =Double.parseDouble(Chinese1);
System.out.println("请输入学生数学成绩:");
String Math1 =sc.nextLine();
double Math =Double.parseDouble(Math1);
//String English1 ="";
double English = 0;
//String Software1 ="";
double Software = 0;
switch(profession) {
case "1":
System.out.println("请输入学生英语成绩:");
String English1 = sc.nextLine();
English = Double.parseDouble(English1);
s.setEnglish(English);
break;
case "2":
System.out.println("请输入学生软件成绩:");
String Software1 =sc.nextLine();
Software =Double.parseDouble(Software1);
s.setSoftware(Software);
break;
}
double total = Chinese+ Math + English + Software;
double aver = total / 3;
s.setprofession(profession);
s.setSid(sid);
s.setName(name);
s.setChinese(Chinese);
s.setMath(Math);
s.settotal(total);
s.setaver(aver);
//将学生对象添加到集合中
array.add(s);
//给出添加成功提示
System.out.println("添加学生成功");
}
//定义一个方法,判断学号是否被使用
public static boolean isUsed(ArrayList<Student> array, String sid){
//如果与集合中的某一学生学号相同,返回ture;如果都不相同,返回false
boolean flag = false;
for (int i = 0; i < array.size(); i++){
Student s = array.get(i);
if (s.getSid().equals(sid)){
flag = true;
break;
}
}
return flag;
}
//定义一个方法,用于查看学生信息
public static void findAllStudent(ArrayList<Student> array) {
//判断集合中是否有数据,如果没有显示提示信息
if (array.size() == 0) {
System.out.println("无信息,请先添加信息再查询");
} else {
//显示表头信息
//\t 其实就是tab键的位置
int Stunum1 =0;
int Stunum2= 0;
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平均分");
//将集合中的元素输出显示 显示英语专业
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
//显示信息
if (s.getprofession().equals("1")) {
//显示信息
//System.out.println("学号\t\t\t\t姓名\t\t语文\t\t数学\t\t英语\t\t总分\t\t平均分");
System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t" + s.getChinese() + "\t\t" + s.getMath()+"\t\t"+ s.getEnglish()+"\t\t"+ s.gettotal()+"\t\t"+ s.getaver());
Stunum1 =Stunum1+1;
}
//System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t" + s.getChinese() + "\t" + s.getMath()+"\t" + s.getEnglish() + "\t" + s.getSoftware() + "\t" + s.gettotal() + "\t" + s.getaver() );
}
if(Stunum1==0) {
System.out.println("英语专业没有学生");
}
System.out.println("软件专业学生信息");
System.out.println("学号\t\t\t\t姓名\t\t\t语文\t\t数学\t\t软件\t\t总分\t\t平均分");
//将集合中的元素输出显示 显示软件专业
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (s.getprofession().equals("2")) {
//显示信息
//System.out.println("学号\t\t\t\t姓名\t\t语文\t\t数学\t\t英语\t\t总分\t\t平均分");
System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t" + s.getChinese() + "\t\t" + s.getMath()+"\t\t"+ s.getSoftware()+"\t\t"+ s.gettotal()+"\t\t"+ s.getaver());
Stunum2 =Stunum2+1;
}
//System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t" + s.getChinese() + "\t" + s.getMath()+"\t" + s.getEnglish() + "\t" + s.getSoftware() + "\t" + s.gettotal() + "\t" + s.getaver() );
}
if(Stunum2==0) {
System.out.println("软件专业没有学生");
}
int num =Stunum1+Stunum2;
System.out.println(Stunum1+"名英语专业学生\t"+Stunum2+"名软件专业学生\n");
System.out.println("共计: "+ num+"名学生\n");
}
}
//定义一个方法,用于删除学生信息
public static void deleteStudent(ArrayList<Student> array) {
if(array.size()==0){
System.out.println("没有学生信息");
}else {
//键盘录入要删除的学生学号,显示提示信息
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要删除的学生学号:");
String sid = sc.nextLine();
//在删除学生操作前,对学号是否存在进行判断
//如果不存在,显示提示信息
//遍历集合将对应学生对象从集合中删除
int index = -1;
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (s.getSid().equals(sid)) {
// array.remove(i);
index = i;
break;
}
}
if (index == -1) {
System.out.println("该学号信息不存在,请重新输入");
} else {
array.remove(index);
//给出提示删除学生成功
System.out.println("删除学生成功");
}
}
}
public static void lookforStudent(ArrayList<Student> array) {
if (array.size() == 0) {
System.out.println("无信息,请先添加信息再查询");
}else {
//键盘录入要查询的学生学号,显示提示信息
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要查询的学生学号:");
String sid = sc.nextLine();
//在查询学生操作前,对学号是否存在进行判断
//如果不存在,显示提示信息
//遍历集合将对应学生对象从集合中展示
int index = -1;
for (int i = 0; i < array.size(); i++) {
Student s = array.get(i);
if (s.getSid().equals(sid)) {
// array.remove(i);
index = i;
break;
}
}
if (index == -1) {
System.out.println("该信息不存在,请重新输入");
} else {
//array.remove(index);
//给出提示删除学生成功
System.out.println("查询学生成功");
Student s = array.get(index);
if (s.getprofession().equals("1")) {
System.out.println("学号\t\t\t\t姓名\t\t\t语文\t\t数学\t\t\t英语\t\t\t总分\t\t\t平均分");
System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t\t" + s.getChinese() + "\t\t\t" + s.getMath() + "\t\t\t" + s.getEnglish() + "\t\t\t" + s.gettotal() + "\t\t\t" + s.getaver());
}
if (s.getprofession().equals("2")) {
System.out.println("学号\t\t\t\t姓名\t\t\t语文\t\t\t数学\t\t\t软件\t\t\t总分\t\t\t平均分");
System.out.println(s.getSid() + "\t\t\t\t" + s.getName() + "\t\t\t" + s.getChinese() + "\t\t\t" + s.getMath() + "\t\t\t" + s.getSoftware() + "\t\t\t" + s.gettotal() + "\t\t\t" + s.getaver());
}
}
}
}
//定义一个方法,用于修改学生信息
public static void updateStudent(ArrayList<Student> array) {
if (array.size() == 0) {
System.out.println("无信息,请先添加信息再更改");
} else {
//键盘输入要修改的学生学号,显示提示信息
Scanner sc = new Scanner(System.in);
System.out.println("请输入你要修改的学生学号:");
String sid = sc.nextLine();
int index = -1;
//遍历结合修改学生的对应信息
for (int i = 0; i < array.size(); i++) {
Student student = array.get(i);
if (student.getSid().equals(sid)) {
index = i;
// array.set(i,s);
break;
}
}
if (index == -1) {
System.out.println("不存在要修改的学生学号,请重新输入");
} else {
//创建一个新的学生对象
//键盘录入要修改的学生信息
Student s = new Student();
System.out.println("请输入学生专业:1英语,2软件:");
String profession = sc.nextLine();
//int profession=Integer.parseInt(profession1);
System.out.println("请输入学生姓名:");
String name = sc.nextLine();
System.out.println("请输入学生语文成绩:");
String Chinese1 = sc.nextLine();
double Chinese = Double.parseDouble(Chinese1);
System.out.println("请输入学生数学成绩:");
String Math1 = sc.nextLine();
double Math = Double.parseDouble(Math1);
double English = 0;
//String Software1 ="";
double Software = 0;
switch (profession) {
case "1":
System.out.println("请输入学生英语成绩:");
String English1 = sc.nextLine();
English = Double.parseDouble(English1);
s.setEnglish(English);
break;
case "2":
System.out.println("请输入学生软件成绩:");
String Software1 = sc.nextLine();
Software = Double.parseDouble(Software1);
s.setSoftware(Software);
break;
}
double total = Chinese + Math + English + Software;
double aver = total / 3;
//s.setSid(sid);
//s.setName(name);
s.setprofession(profession);
s.setSid(sid);
s.setName(name);
s.setChinese(Chinese);
s.setMath(Math);
s.settotal(total);
s.setaver(aver);
array.set(index, s);
//给出修改成功提示
System.out.println("修改学生信息成功");
}
}
}
}
其中的各个函数
case "0":
// ("添加学生");
addStudent(array);
case "1":
// ("删除学生");
deleteStudent(array);
case "2":
// ("根据学号查询学生");
lookforStudent(array);
case "3":
// ("查看所有学生");
findAllStudent(array);
case "4":
// ("修改学生信息");
updateStudent(array);
case "5":
("退出系统");
//
程序链接
百度云 java学生成绩管理系统
提取码 提取码:5q5k