diff --git "a/37 \347\216\213\346\231\264/2022.12.20\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\232.md" "b/37 \347\216\213\346\231\264/2022.12.20\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\232.md" new file mode 100644 index 0000000000000000000000000000000000000000..543e4d175d98189d6576e9cc5808a8e0176e7ebd --- /dev/null +++ "b/37 \347\216\213\346\231\264/2022.12.20\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\357\274\232.md" @@ -0,0 +1,117 @@ +【本周大作业】: +============================== +- ### 欢迎使用3班学生管理系统 - +- 1.浏览所有学生信息 - +- 2.添加学生信息 - +- 3.修改学生信息 - +- 4.删除学生信息 - +- 5.查询学生信息 - +- 6.退出管理系统 - + ------------------------------ + 请输入对应的数字选择你需要的功能: + + ```java + import java.util.Scanner; + + public class StudentSystem { + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + + String[] student = new String[46]; + student[0] = "苏清华"; + student[1] = "林佳泽"; + student[3]="徐雨晴"; + + while (true){ + Welcome(); + choice(sc.nextInt(), student, sc); + } + + } + + //欢迎界面 + public static void Welcome() { + System.out.println( + "\n============================" + + "\n- 欢迎使用3班学生管理系统 --" + + "\n- 1.浏览所有学生信息 -" + + "\n- 2.添加学生信息 -" + + "\n- 3.修改学生信息 -" + + "\n- 4.删除学生信息 -" + + "\n- 5.查询学生信息 -" + + "\n- 6.退出管理系统 -" + + "\n =========================" + + "\n请输入对应的数字选择你需要的功能:"); + } + + //菜单选择 + public static void choice(int num, String[] stu, Scanner sc) { + switch (num) { + case 1: + Allstudent(stu); + break; + case 2: + addstudent(stu); + break; + case 3: + break; + case 4: + break; + case 5: + break; + case 6: + break; + default: + System.out.println("你输入的选项错误"); + } + } + + public static void Allstudent(String[] stu) { + System.out.println("3班学生如下:"); + for (String name : stu) { + if (name==null){ + continue; + } + System.out.println(name + "\t"); + } + } + + public static void addstudent(String[] stu) { + System.out.println("请输入你要查找的学生"); + String name = sc.next(); + int index = search(stu, name); + if (index != -1) { + System.out.println("该学生已经在数据库了,请不要重复添加"); + } else { + int nullIndex = search(stu,null); + stu[nullIndex] = name; + System.out.println("添加成功"); + + } + } + + + public static int search(String[] stu, String str) { + int index = -1; + if (str == null) { + for (int i = 0; i < stu.length; i++) { + if (stu[i]==null){ + index = i; + break; + } + } + }else { + for (int i = 0; i < stu.length; i++) { + if (str.equals(stu[i])) { + index=i; + return index; + } + } + } + return index; + } + } + ``` + + \ No newline at end of file