测试:
import java.util.*;
import java.util.function.Consumer;
public class Main {
public static void main(String[] args) {
System.out.println("欢迎来到学生成绩管理系统");
ArrayList<Teachers> teachers = new ArrayList<>();//教师
ArrayList<Students> students = new ArrayList<>();//学生
Teachers(teachers);
students(students);
while (true) {
A();
B(teachers, students);
}
}
public static void A() {
System.out.println("请选择:1教师\t\t\t2学生\t\t3管理员\t\t4退出系统");
}
//教师
public static void Teachers(ArrayList<Teachers> teachers) {
ArrayList<String> list = new ArrayList<>();
list.add("计算机");
list.add("美术");
ArrayList<String> list1 = new ArrayList<>();
list1.add("数学");
list1.add("英语");
list1.add("语文");
Teachers teachers1 = new Teachers("001", "liyuan", list);
Teachers teachers2 = new Teachers("002", "zhangsan", list1);
teachers.add(teachers1);
teachers.add(teachers2);
}
//学生
public static void students(ArrayList<Students> students) {
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
map.put("计算机", 0);
map.put("英语", 0);
LinkedHashMap<String, Integer> map2 = new LinkedHashMap<>();
map2.put("美术", 0);
map2.put("数学", 0);
map2.put("计算机", 0);
Students students1 = new Students("153001", "xiaoming", map);
Students students2 = new Students("153002", "liiy", map2);
students.add(students1);
students.add(students2);
}
//选择
public static void B(ArrayList<Teachers> teachers, ArrayList<Students> students) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
switch (a) {
case 1:
//教师
Te(teachers, students);
break;
case 2:
//学生
Students(students);
break;
case 3:
//管理员
D(teachers, students);
break;
case 4:
//退出
System.out.println("退出");
break;
default:
System.out.println("没有选项");
}
}
//管理员
public static void D(ArrayList<Teachers> teachers, ArrayList<Students> students) {
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 100; i++) {
System.out.println("1添加教师\t\t2添加学生\t\t3修改教师信息\t\t4修改学生信息\t5查看信息\t6返回");
String a = scanner.next();
switch (a) {
case "1":
setTe(teachers);
break;
case "2":
setSu(students);
break;
case "3":
modifyTe(teachers);
break;
case "4":
modifySu(students);
break;
case "5":
C(teachers, students);
break;
case "6":
System.out.println("返回");
return;
default:
System.out.println("没有选项");
}
}
}
public static void C(ArrayList<Teachers> teachers, ArrayList<Students> students) {
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 100; i++) {
System.out.println("1查看教师信息\t\t2查看所用学生信息\t\t3输入姓名查看教师信息\t\t4输入姓名查看学生信息\t5返回");
String a = scanner.next();
switch (a) {
case "1":
//查看教师
seeTe(teachers);
break;
case "2":
//查看学生
seeSu(students);
break;
case "3":
//入姓名查看教师
seeName(teachers);
break;
case "4":
SeeName(students);
//输入姓名查看学生
break;
case "5":
System.out.println("退出");
return;
}
}
}
//查看教师
public static void seeTe(ArrayList<Teachers> teachers) {
System.out.println("序号\t工号\t姓名\t所上课课程");
for (int i = 0; i < teachers.size(); i++) {
Teachers teachers1 = teachers.get(i);
ArrayList<String> str = teachers1.getStr();
System.out.print(i + 1 + "\t" + teachers1.getId() + " " + teachers1.getName() + " ");
for (String s : str) {
System.out.print(s + " ");
}
System.out.println();
}
}
//查看学生
public static void seeSu(ArrayList<Students> list) {
System.out.println("序号\t学号\t姓名\t所选课程");
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
System.out.println(i + 1 + "\t" + students.getId() + " " + students.getName());//输入id和姓名
System.out.println("该生所选课程及对应成绩如下");
Set<Map.Entry<String, Integer>> entries = students.getStr().entrySet();//map的输出方式
entries.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
System.out.println(key + "\t\t" + value);
}
});
}
}
//添加教师
public static void setTe(ArrayList<Teachers> list) {
Teachers teachers = new Teachers();
ArrayList<String> list1 = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
System.out.println("请输入教师工号");
String a = scanner.next();
teachers.setId(a);
System.out.println("请输入教师姓名");
String b = scanner.next();
teachers.setName(b);
System.out.println("请输入教师本学期讲授课程的数量");
int c = scanner.nextInt();
System.out.println("请输入教师所上课程,用空格隔开");
for (int i = 0; i < c; i++) {
String d = scanner.next();
list1.add(d);
teachers.setStr(list1);
}
list.add(teachers);
}
//输入姓名查看
public static void seeName(ArrayList<Teachers> teachers) {
System.out.println("请输入老师名字");
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
for (int i = 0; i < teachers.size(); i++) {
Teachers teachers1 = teachers.get(i);
if (teachers1.getName().equals(a)) {
System.out.println("序号\t工号\t姓名\t所上课课程");
System.out.print(i + 1 + "\t" + teachers1.getId() + " " + teachers1.getName()+" ");
for (String s : teachers1.getStr()) {
System.out.print(s+" ");
}
System.out.println();
}
}
}
//输入姓名查看
public static void SeeName(ArrayList<Students>list){
System.out.println("请输入学生名字");
Scanner scanner = new Scanner(System.in);
String a = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
if (a.equals(students.getName())) {
System.out.println("序号\t学号\t姓名\t所选课程");
System.out.println(i + 1 + "\t" + students.getId() + " " + students.getName());//输入id和姓名
System.out.println("该生所选课程及对应成绩如下");
Set<Map.Entry<String, Integer>> entries = students.getStr().entrySet();//map的输出方式
entries.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
System.out.println(key + "\t\t" + value);
}
});
}
}
}
//添加学生
public static void setSu(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
//创建一个学生类
Students students = new Students();
System.out.println("请输入学生学号");
String id = scanner.next();
students.setId(id);
System.out.println("请输入学生名字");
String name = scanner.next();
students.setName(name);
System.out.println("请输入该本学期讲选课程的数量");
int c = scanner.nextInt();
System.out.println("请输入学生所选课程名称,每个课程用回车隔开");
for (int i = 0; i < c; i++) {
String d = scanner.next();
map.put(d, 0);
students.setStr(map);
}
list.add(students);
}
//修改教师信息
public static void modifyTe(ArrayList<Teachers> list) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> strings = new ArrayList<>();
System.out.println("请输入老师名字");
String name = scanner.next();
for (int i = 0; i < list.size(); i++) {
Teachers teachers = list.get(i);//集合全部数
if (teachers.getName().equals(name)) {//名字符合进入
System.out.println("请输入教师本学期讲授课程的数量");
int c = scanner.nextInt();
System.out.println("请输入教师所上课程,用空格隔开");
for (int i1 = 0; i1 < c; i1++) {
String d = scanner.next();
strings.add(d);//储存
teachers.setStr(strings);//替换
}
}
}
}
//选课
public static void Class(ArrayList<Students>list){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学号");
String id = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
if (students.getId().equals(id)) {
System.out.println("请输入要添加的课程的数量");
int c = scanner.nextInt();
System.out.println("请输入想选课程,用空格隔开,不能重复");
for (int i1 = 0; i1 < c; i1++) {
String d = scanner.next();
students.getStr().put(d,0);
}
}
}
}
//修改学生信息
public static void modifySu(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
LinkedHashMap<String, Integer> Map = new LinkedHashMap<>();
System.out.println("请输入学生名字");
String name = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
if (students.getName().equals(name)) {
System.out.println("请输入学生本学期讲授课程的数量");
int c = scanner.nextInt();
System.out.println("请输入学生所上课程,用空格隔开");
for (int i1 = 0; i1 < c; i1++) {
String d = scanner.next();
Map.put(d, 0);
students.setStr(Map);
}
}
}
}
//教师登入
public static void Te(ArrayList<Teachers> list, ArrayList<Students> list2) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入教工号");
String id = scanner.next();
for (int i = 0; i < list.size(); i++) {
Teachers teachers = list.get(i);
if (teachers.getId().equals(id)) {
for (int j = 0; j < 100; j++) {
System.out.println("请选择:0选课名单\t\t1录入成绩\t\t2查看成绩\t\t3修改成绩\t4提交成绩\t5退出");
String d = scanner.next();
switch (d) {
case "0":
SeeClass(list2);
break;
case "1":
EnterGrades(list2);
break;
case "2":
ViewGrades(list2);
break;
case "3":
setGrades(list2);
break;
case "4":
System.out.println("提交成绩");
break;
case "5":
System.out.println("0");
return;
}
}
}
}
}
public static void Students(ArrayList<Students>list){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学号");
String id = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students teachers = list.get(i);
if (teachers.getId().equals(id)) {
for (int j = 0; j < 100; j++) {
System.out.println("请选择:0选课信息\t\t1查看成绩\t\t2选课\t\t3退出");
String d = scanner.next();
switch (d) {
case "0":
seeClass(list);
break;
case "1":
VG(list);
break;
case "2":
Class(list);
break;
case "3":
System.out.println("退出");
return;
}
}
}
}
}
//学生查看选课信息
public static void seeClass(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入学号");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
if (Classname.equals(students.getId())) {
Set<Map.Entry<String, Integer>> entries = students.getStr().entrySet();
entries.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
System.out.println(key+" ");
}
});
}
}
}
//查看学生选课信息
public static void SeeClass(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入授课信息");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
Set<Map.Entry<String, Integer>> entries = students.getStr().entrySet();
entries.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
if (key.equals(Classname)) {
System.out.println("下列同学");
System.out.println(students.getId() + "\t\t" + students.getName());
}
}
});
}
}
//录入成绩
public static void EnterGrades(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
String c = "T";
while ("T".equals(c)) {
System.out.println("请输入录入的成绩的课程名称");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);//全
Set<Map.Entry<String, Integer>> entries = students.getStr().entrySet();
entries.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();//键
Integer value = stringIntegerEntry.getValue();//值
if (key.equals(Classname)) {
System.out.println("姓名");
String name = scanner.next();
if (students.getName().equals(name)) {
System.out.println("成绩");
int number = scanner.nextInt();
students.getStr().put(Classname, number);
}
}
}
});
}
System.out.println("是否继续,继续输入T,不继续输入F");
c = scanner.next();
}
}
//学生查看选课成绩
public static void VG(ArrayList<Students>list){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查看的课程名称");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
Set<Map.Entry<String, Integer>> set = students.getStr().entrySet();
set.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
if (Classname.equals(key)) {
System.out.println("学生学号\t学生姓名\t课程分数");
System.out.println(students.getId() + " " + students.getName() + " " + value);
System.out.println("该课程的平均分,最高分,最低分分别是");
System.out.println(value + "," + value + "," + value);
}
}
});
}
}
//查看成绩
public static void ViewGrades(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查看的课程名称");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
Set<Map.Entry<String, Integer>> set = students.getStr().entrySet();
set.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
if (Classname.equals(key)) {
System.out.println("学生学号\t学生姓名\t课程分数");
System.out.println(students.getId() + " " + students.getName() + " " + value);
System.out.println("该课程的平均分,最高分,最低分分别是");
System.out.println(value + "," + value + "," + value);
}
}
});
}
}
//修改成绩
public static void setGrades(ArrayList<Students> list) {
Scanner scanner = new Scanner(System.in);
String c = "T";
while ("T".equals(c)) {
System.out.println("请输入要修改的课程名称");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
Set<Map.Entry<String, Integer>> set = students.getStr().entrySet();
set.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
if (Classname.equals(key)) {
System.out.println("请输入学生姓名");
String name = scanner.next();
if (name.equals(students.getName())) {
System.out.println("请输入该生的新成绩");
int a = scanner.nextInt();
students.getStr().put(Classname, a);
}
}
}
});
}
System.out.println("是否继续,继续输入T,不继续输入F");
c = scanner.next();
}
}
//学生查看成绩
public static void seeStudents(ArrayList<Students>list){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入要查看的课程名称");
String Classname = scanner.next();
for (int i = 0; i < list.size(); i++) {
Students students = list.get(i);
Set<Map.Entry<String, Integer>> set = students.getStr().entrySet();
set.forEach(new Consumer<Map.Entry<String, Integer>>() {
@Override
public void accept(Map.Entry<String, Integer> stringIntegerEntry) {
String key = stringIntegerEntry.getKey();
Integer value = stringIntegerEntry.getValue();
if (Classname.equals(key)) {
System.out.println("学生学号\t学生姓名\t课程分数");
System.out.println(students.getId() + " " + students.getName() + " " + value);
System.out.println("该课程的平均分,最高分,最低分分别是");
System.out.println(value + "," + value + "," + value);
}
}
});
}
}
}
学生类:
import java.util.LinkedHashMap;
public class Students {
private String id;
private String name;
private LinkedHashMap<String,Integer> str;
public Students() {
}
public Students(String id, String name, LinkedHashMap<String, Integer> str) {
this.id = id;
this.name = name;
this.str = str;
}
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 LinkedHashMap<String, Integer> getStr() {
return str;
}
public void setStr(LinkedHashMap<String, Integer> str) {
this.str = str;
}
}
教师类:
import java.util.ArrayList;
public class Teachers {
private String id;
private String name;
private ArrayList<String> str;
public Teachers() {
}
public Teachers(String id, String name, ArrayList<String> str) {
this.id = id;
this.name = name;
this.str = str;
}
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 ArrayList<String> getStr() {
return str;
}
public void setStr(ArrayList<String> str) {
this.str = str;
}
}