From a0511f8e2347963f95eb36270f46a2fd8e68527d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=A9=E4=B8=9C?= <3187628460@qq.com> Date: Thu, 22 Dec 2022 08:45:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\347\263\273\347\273\237.md" | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 "23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" diff --git "a/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000..a54603d --- /dev/null +++ "b/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,99 @@ +# 作业 + +```java +import java.lang.reflect.Array; +import java.util.Scanner; + +public class Main { + static Scanner sc=new Scanner(System.in); + public static void main(String[] args) { + String [] Stu=new String[10]; //记入学生的数组(数据库替代品) + Stu [0]="小强"; + Main:while (true){ + System.out.println("========================================="); + System.out.println("\t"+"-"+"\t"+"欢迎使用3班管理系统"+"\n"+ + "\t"+"-"+"\n"+ + "\t"+"-"+"\t"+"1.浏览所有学生信息 -"+"\t"+"\n"+ + "\t"+"-"+"\t"+"2.添加学生信息 -"+"\t"+"\n"+ + "\t"+"-"+"\t"+"3.修改学生信息 -"+"\t"+"\n"+ + "\t"+"-"+"\t"+"4.删除学生信息 -"+"\t"+"\n"+ + "\t"+"-"+"\t"+"5.查询学生信息 -"+"\t"+"\n"+ + "\t"+"-"+"\t"+"6.退出管理系统 -"+"\t"); + System.out.println("========================================="); + System.out.println("输入相对应的数字选择你需要的功能:"); + int Choice=sc.nextInt(); + switch (Choice){ + case 1: + System.out.println("你选择了浏览所有学生信息"); + p1(Stu); + break; + case 2: + System.out.println("你选择了添加学生信息"); + add(Stu); + break; + case 3: + System.out.println("你选择了修改学生信息"); + break; + case 4: + System.out.println("你选择了删除学生信息"); + break; + case 5: + System.out.println("你选择了查询学生信息"); + break; + case 6: + System.out.println("你选择了退出管理系统"); + System.out.println("退出成功"); + break Main; + default: + System.out.println("无效数据"); + } + } + } + //1.浏览所有学生信息 + public static void p1(String [] p1){ + System.out.println("以下为该班级的学生名单为:"); + for (String name:p1) { + if(name!=null) { + System.out.println(name+"\t"); + } + } + } + /*2.添加学生信息 + * 分析: + * 1.添加学生需要找到空位置才能添加不然会覆盖以前的学生 + * 2.需要一个扫描器接收学信息*/ + public static void add(String[] p2){ + int NullInt=NullInt(p2); + if (NullInt==-1){ + System.out.println("没有空位置了"); + } + else { + System.out.println("有空位置为"+NullInt+"\n"+"请输入学生姓名"); + String Name= sc.next(); + p2[NullInt]=Name; + } + System.out.println("==========================="); + for (int i=0;i< p2.length;i++){ + if (p2[i]!=null){ + System.out.print(p2[i]+" "); + } + } + System.out.println("增加成功"); + } + //3.修改学生 + //判断是否为空位置:因为修改,删除和添加都需要使用到这个东西所有单独写出这个东西 + public static int NullInt(String[] Null){ + int NullInt=-1; + for (int i= 1;i Date: Tue, 27 Dec 2022 00:17:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=9D=A2=E5=90=91=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E5=92=8C=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...41\347\220\206\347\263\273\347\273\237.md" | 106 +++++-- ...45\351\227\250\347\254\224\350\256\260.md" | 274 ++++++++++++++++++ 2 files changed, 361 insertions(+), 19 deletions(-) create mode 100644 "23\345\217\267 \351\273\204\346\265\251\344\270\234/20221223 \351\235\242\345\220\221\345\257\271\350\261\241\345\205\245\351\227\250\347\254\224\350\256\260.md" diff --git "a/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" index a54603d..9f1623b 100644 --- "a/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" +++ "b/23\345\217\267 \351\273\204\346\265\251\344\270\234/20221220 \345\255\246\347\224\237\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -1,14 +1,18 @@ # 作业 +学生管理系统 + ```java import java.lang.reflect.Array; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in); + private static Object equals; + public static void main(String[] args) { - String [] Stu=new String[10]; //记入学生的数组(数据库替代品) - Stu [0]="小强"; + String [] Stu=new String[2]; //记入学生的数组(数据库替代品) +// Stu [0]="小强";Stu[1]="小小"; Main:while (true){ System.out.println("========================================="); System.out.println("\t"+"-"+"\t"+"欢迎使用3班管理系统"+"\n"+ @@ -33,12 +37,15 @@ public class Main { break; case 3: System.out.println("你选择了修改学生信息"); + change(Stu); break; case 4: System.out.println("你选择了删除学生信息"); + delited(Stu); break; case 5: System.out.println("你选择了查询学生信息"); + Scanner(Stu); break; case 6: System.out.println("你选择了退出管理系统"); @@ -51,12 +58,19 @@ public class Main { } //1.浏览所有学生信息 public static void p1(String [] p1){ - System.out.println("以下为该班级的学生名单为:"); - for (String name:p1) { - if(name!=null) { - System.out.println(name+"\t"); + int pd=NullInt(p1); + if (pd!=0){ + System.out.println("以下为该班级的学生名单为:"); + for (String name:p1) { + if(name!=null) { + System.out.println(name+"\t"); + } } } + else { + System.out.println("该班级暂时没有学生"); + } + } /*2.添加学生信息 * 分析: @@ -71,29 +85,83 @@ public class Main { System.out.println("有空位置为"+NullInt+"\n"+"请输入学生姓名"); String Name= sc.next(); p2[NullInt]=Name; - } - System.out.println("==========================="); - for (int i=0;i< p2.length;i++){ - if (p2[i]!=null){ - System.out.print(p2[i]+" "); + System.out.println("==========================="); + for (int i=0;i< p2.length;i++){ + if (p2[i]!=null){ + System.out.print(p2[i]+" "); + } } + System.out.println("增加成功"); } - System.out.println("增加成功"); } //3.修改学生 - //判断是否为空位置:因为修改,删除和添加都需要使用到这个东西所有单独写出这个东西 + /*分析 + * 先要一个扫描器接收姓名 + * 需要判断并找到该姓名的位置 + * 进行覆盖*/ + public static void change(String[] p3){ + int p=place(p3); + if (p==-1){ + System.out.println("找不到该学生"); + } + else { + System.out.println("请输入新名字"); + String newName= sc.next(); + p3[p]=newName; + System.out.println("修改成功"); + } + } + //4.删除学生 + /*分析:需要一个扫描器接收名字 + * 1.需要判断是否有该学生 + * 2.需要找到该学生的位置 + * 3.使其等于null + * 4.如果找不到该学生就输出无法找到该学生*/ + public static void delited(String[] p4){ + int p=place(p4); + if (p==-1){ + System.out.println("找不到该学生"); + } + else { + p4[p]=null; + System.out.println("删除成功"); + } + } + /*5.浏览学生信息 + * 1需要扫描器接收学生姓名 + * 2判断是否有该学生 + * 3如果有则输出*/ + public static void Scanner (String[]p5){ + int p = place(p5); + if (p==-1){ + System.out.println("找不到该学生"); + } + else { + System.out.println("该学生的基本信息为"+p5[p]); + } + } + //判断是否有空位置:因为修改,删除和添加都需要使用到这个东西所有单独写出这个东西 public static int NullInt(String[] Null){ int NullInt=-1; - for (int i= 1;i