2019.12.02 学生学籍管理系统

/** * erwei.java * com.oracle.array * * Function: TODO  * *   ver     date      author * ────────────────────────────────── *    2019年12月1日 17671 * * Copyright (c) 2019, TNT All Rights Reserved.*/
package com.oracle.array;
import java.util.Scanner;
import javax.xml.transform.Templates;
/** * ClassName:erwei Function: TODO ADD FUNCTION Reason: TODO ADD REASON * * @author 17671 * @version * @since Ver 1.1 * @Date 2019年12月1日 下午7:07:02 * * @see */public class xuejixitong {public static Scanner scanner = new Scanner(System.in);public static String[][] student = new String[5][3];
public static void main(String[] args) {menu();}public static void menu() {boolean flag = true;while (flag) {System.out.println("*********学籍管理系统*********");System.out.println("        1.添加学生信息                      ");System.out.println("        2.删除学生信息                      ");System.out.println("        3.修改学生信息                      ");System.out.println("        4.查询学生信息                      ");System.out.println("        5.展示学生信息                      ");System.out.println("        6.退出系统                              ");System.out.println("**************************");System.out.println("请选择:");String choice = scanner.nextLine();switch (choice) {case "1":System.out.println("请按照id;姓名;性别  格式录入学生信息");String stuinfo=scanner.nextLine();if (stuinfo.equals("")) {System.out.println("请好好输入!");}else {String[] temp=stuinfo.split(";");    addStudent(temp[0],temp[1],temp[2]);    show();}//System.out.println("请输入学号:");//String id=scanner.nextLine();//System.out.println("请输入姓名:");//String name=scanner.nextLine();//System.out.println("请输入性别:");//String sex=scanner.nextLine();//addStudent(id, name, sex);break;case "2":System.out.println("请输入要删除学生的学号:");String id=scanner.nextLine();if (id.endsWith("")) {System.out.println("请重新输入:");}else {deleteStudent(id);show();}break;case "3":System.out.println("请输入要修改学生的学号:");String stuid=scanner.nextLine();System.out.println("请输入要修改的姓名:");String newName=scanner.nextLine();if (stuid.equals("")) {System.out.println("请重新输入");}else {updateStudent(stuid, newName);show();}break;case "4"://选择查询方式System.out.println("请按照0(id)1(姓名)2(性别);id;姓名;性别 查询  ");String mode=scanner.nextLine();if (mode.equals("")) {System.out.println("请重新输入:");}else {String[] temp1=mode.split(";");queryStudent(temp1[0], temp1[1], temp1[2], temp1[3]);}break;case "5":show();break;case "6":flag = false;System.out.println("欢迎下次使用!");break;
default:System.out.println("命令无效。请重新输入!");break;}}}
// 添加学生信息public static void addStudent(String id, String name, String sex) {//表示学生数组是否已满boolean ifEmpty=false;for (int i = 0; i < student.length; i++) {if(student[i][0]==null) {student[i][0]=id;student[i][1]=name;student[i][2]=sex;ifEmpty=true;System.out.println("*************添加学生成功!*************");break;}}if (ifEmpty==false) {System.out.println("添加学生失败,数组已满");}}
// 删除学生信息public static void deleteStudent(String id) {//是否找到要删除的数据boolean flag=false;for (int i = 0; i < student.length; i++) {if (student[i][0]!=null) {if (student[i][0].equals(id)) {//删除当前学生数据 student[i][0]=null;student[i][1]=null;student[i][2]=null;flag=true;System.out.println("删除学生信息成功!");break;}}}//没有找到该学生if (flag=false) {System.out.println("没有找到该学生的信息");}}
// 修改学生信息public static void updateStudent(String id, String name) {//是否找到要修改的数据boolean flag=false;for (int i = 0; i < student.length; i++) {if (student[i][0]!=null) {if (student[i][0].equals(id)) {//修改当前学生数据 student[i][1]=name;flag=true;System.out.println("修改学生信息成功!");break;}}}//没有找到该学生if (flag=false) {System.out.println("没有找到该学生的信息");}}
// 根据不同模式查询学生信息public static void queryStudent(String mode, String id, String name, String sex) {//是否找到要查询的数据boolean flag=false;System.out.println("***************学生名单***************");System.out.println("学号\t\t姓名\t\t性别");System.out.println("***********************************");for (int i = 0; i < student.length; i++) {if (student[i][0]!=null) {switch (mode) {case "0":if (student[i][0].equals(id)) {System.out.println(student[i][0]+"\t\t"+student[i][1]+"\t\t"+student[i][2]);flag=true;break;}else {System.out.println("没有找到该id的学生");}break;case "1"://模糊查询if (student[i][1].contains(name)) {System.out.println(student[i][0]+"\t\t"+student[i][1]+"\t\t"+student[i][2]);flag=true;}else {System.out.println("没有该姓名的学生");}break;case "2":if (student[i][2].equals(sex)) {System.out.println(student[i][0]+"\t\t"+student[i][1]+"\t\t"+student[i][2]);flag=true;}break;
default:System.out.println("没有该模式");break;}}}if (flag=false) {System.out.println("没有找到目标数据!");}System.out.println("***********************************");}
// 展示学生信息public static void show() {System.out.println("***************学生名单***************");System.out.println("学号\t\t姓名\t\t性别");System.out.println("***********************************");for (int i = 0; i < student.length; i++) {//student[i]不为空 student[i][0]表示每行第一个数if (student[i][0] == null) {System.out.println("没有数据!");} else {for (int j = 0; j < student[i].length; j++) {System.out.print(student[i][j] + "\t\t");}System.out.println();}}System.out.println("***********************************");}}

猜你喜欢

转载自www.cnblogs.com/aojie/p/11973364.html