From def450dd339bdb2765a3a6727da3bf1141c0f69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=AE=8F=E6=89=AC?= Date: Wed, 21 Dec 2022 19:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...71\347\233\256\344\275\234\344\270\232.md" | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 "14 \345\256\213\345\256\217\346\211\254/20221220\345\205\263\344\272\2163\347\217\255\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\347\232\204\351\241\271\347\233\256\344\275\234\344\270\232.md" diff --git "a/14 \345\256\213\345\256\217\346\211\254/20221220\345\205\263\344\272\2163\347\217\255\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\347\232\204\351\241\271\347\233\256\344\275\234\344\270\232.md" "b/14 \345\256\213\345\256\217\346\211\254/20221220\345\205\263\344\272\2163\347\217\255\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\347\232\204\351\241\271\347\233\256\344\275\234\344\270\232.md" new file mode 100644 index 0000000..41c22fb --- /dev/null +++ "b/14 \345\256\213\345\256\217\346\211\254/20221220\345\205\263\344\272\2163\347\217\255\345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237\347\232\204\351\241\271\347\233\256\344\275\234\344\270\232.md" @@ -0,0 +1,148 @@ +# 项目:3班学生管理系统 + +```java +import java.util.Scanner; +public class 学生管理系统 { + static Scanner sc = new Scanner(System.in); + public static void main(String[] args) { + String[] xuesheng = new String[10]; + xuesheng[0] = "邓琪"; + xuesheng[1] = "蔡泽钦"; + xuesheng[2] = "钟梓鑫"; + xuesheng[3] = "黄梓镜"; + xuesheng[4] = "郑玮锋"; + xuesheng[5] = "宋宏扬"; + System.out.println(" ==============================\n" + + " - 欢迎使用3班学生管理系统 -\n" + + " - 1.所有学生信息 -\n" + + " - 2.添加学生信息 -\n" + + " - 3.修改学生信息 -\n" + + " - 4.删除学生信息 -\n" + + " - 5.查询学生信息 -\n" + + " - 6.退出管理系统 -\n" + + " ==============================\n"); + while (true){ + shouye(); + xuanze(sc.nextInt(),xuesheng); + } + } + //首页菜单 + public static void shouye () { + System.out.println(" 请输入对应的数字选择你需要的功能:"); + } + //选择服务 + public static void xuanze (int num,String[] xuesheng) { + System.out.println(); + switch (num){ + case 1: + System.out.println(" - 所有学生信息"); + liulan(xuesheng); + break; + case 2: + System.out.println(" - 添加学生信息"); + tianjia(xuesheng); + break; + case 3: + System.out.println(" - 修改学生信息"); + xiugai(xuesheng); + break; + case 4: + System.out.println(" - 删除学生信息"); + shanchu(xuesheng); + break; + case 5: + System.out.println(" - 查询学生信息"); + chaxun(xuesheng); + break; + case 6: + System.out.println(" 即将退出3班学生管理系统,欢迎下次使用!"); + System.exit(0); + break; + default: + System.out.println("请输入正确的服务号码!"); + } + } + //1.浏览所有学生信息 + public static void liulan (String[] xuesheng) { + for (String name:xuesheng) { + if (name == null) { + continue; + }else { + System.out.println(name); + } + } + System.out.println(); + } + //2.添加学生信息 + public static void tianjia (String[] xuesheng) { + System.out.println("请输入学生信息:"); + String name = sc.next(); + int index = suoyin(xuesheng,name); + if (index != -1) { + System.out.println("该学生已存在,请勿重复添加!"); + }else { + int nullIndex = suoyin(xuesheng,null); + xuesheng[nullIndex] = name; + System.out.println(name + "同学已加入到3班学生管理系统!"); + } + } + //3.修改学生信息 + public static void xiugai (String[] xuesheng){ + System.out.println("请输入要修改信息的学生姓名:"); + String name = sc.next(); + System.out.println("请输入修改后的内容:"); + String nameEr = sc.next(); + int index = suoyin(xuesheng,name); + if (index == -1) { + System.out.println("该学生不存在!"); + }else { + xuesheng[index] = nameEr; + System.out.println("该生的信息已修改完成!"); + } + } + //4.删除学生信息 + public static void shanchu (String[] xuesheng){ + System.out.println("请输入要删除的学生姓名"); + String name = sc.next(); + int index = suoyin(xuesheng,name); + if (index == -1) { + System.out.println("该学生不存在!"); + }else { + xuesheng[index] = null; + System.out.println("该生已从3班学生管理系统中删除!"); + } + } + //5.查询学生信息 + public static void chaxun (String[] xuesheng) { + System.out.println("请输入要查询的学生姓名:"); + String name = sc.next(); + int index = suoyin(xuesheng,name); + if (index == -1) { + System.out.println("3班没有查到该学生!"); + }else { + System.out.println("该学生的信息为:" + xuesheng[index]); + } + } + //信息下标索引 + public static int suoyin (String[] xuesheng,String str) { + int index = -1; + if (str == null) { + for (int i = 0 ; i < xuesheng.length ; i ++) { + if (xuesheng[i] == null) { + index = i; + break; + } + } + }else { + for (int i = 0; i < xuesheng.length; i++) { + if (str.equals(xuesheng[i])) { + index = i; + return index; + } + } + } + return index; + } +} +``` + -- Gitee