diff --git "a/03 \345\276\220\351\233\250\346\231\264/20221220 \345\255\246\347\224\237\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237.md" "b/03 \345\276\220\351\233\250\346\231\264/20221220 \345\255\246\347\224\237\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237.md" new file mode 100644 index 0000000000000000000000000000000000000000..c2adf6d3d99b75f7fd52f0cb97f544148e347def --- /dev/null +++ "b/03 \345\276\220\351\233\250\346\231\264/20221220 \345\255\246\347\224\237\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237.md" @@ -0,0 +1,131 @@ +```java +import java.util.Scanner; + +public class class16 { + //1.需求,设计一个java程序,来管理3班的学生信息 + //2.学生信息包括:学会、姓名、性别、java成绩 + //3.系统功能:添加学生,修改学生,删除学生,查询学生,浏览所有学生 + static Scanner sc = new Scanner(System.in); + + public static void main(String[] args) { + /* + 欢迎界面、菜单、添加学生模块、修改学生、删除、查找、浏览所有学生、退出系统 + */ + String[] students = new String[10]; + students[0] = "苏"; + students[1] = "林"; + + while (true){ + start(); + chicemenu(sc.nextInt(), students,sc); + } + + } + + //1.欢迎界面 + public static void start() { + System.out.println("================================" + + "\n 欢迎使用3班学生信息管理系统 -" + + "\n- \t\t1.浏览所有学生信息\t\t -" + + "\n- \t\t2.添加学生信息\t\t -" + + "\n- \t\t3.修改学生信息\t\t -" + + "\n- \t\t4.删除学生信息\t\t -" + + "\n- \t\t5.查询学生信息\t\t -" + + "\n- \t\t6.退出管理系统\t\t -" + + "\n ================================ " + + "\n 请输入对应的数字选择你需要的功能:"); + } + + //2.选择菜单 + public static void chicemenu(int num, String[] stu,Scanner sc) { + while (true){ + switch (num) { + case 1: + //1.浏览所有学生信息 + //System.out.println(Allstudents(stu)); + Allstudents(stu); + break; + case 2: + //2.添加学生信息 + addstudents(stu); + break; + case 3: + //3.修改学生信息 + break; + case 4: + //4.删除学生信息 + break; + case 5: + //5.查询学生信息 + break; + case 6: + //6.退出管理系统 + break; + default: + System.out.println("选项错误!"); + } + } + + + } + + public static void Allstudents(String[] stu) { + System.out.println("3班现在以下学生:"); + for (String name : stu) { + //1.当学生为null是+时,跳过,输出下一个 + if (name == null) { + continue; + } + System.out.println(name + "\t"); + + //2.当姓名不为null时,输出 + // if (name!=null){ + //System.out.println(name+"\t"); + //} + } + } + + //4.添加学生信息 + public static void addstudents(String[] stu) { + //先找出没有人的位置,也就是第一个null的位置 + //然后将它改成你要添加的姓名 + 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(); + } + } + + //4.1 把找位置的功能,独立出来,做一个方法,返回找到的位置 + public static int search(String[] stu, String str) { + //定义一个索引变量 + int index = -1; //在数组中,0表示第一个数,-1就表示不存在 + if (str == null) { //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; + + } +} + +``` +