String stuId; //学号
String stuName; //姓名
}
public class StuManager{
public static void main(String[] args){
java.util.Scanner sc = new java.util.Scanner(System.in);
//一、向内存要空间,保存要处理的数据
//String[] names = new String[35];
//String[] ids = new String[35];
Student[] stus = new Student[35];
String adminName = null;
String adminPassword = null;
int count = 0; //代表当前班级内有多少个学生
boolean isLogin = false; //标志变量,标识是否登录
//二、对数据进行业务处理
//2.1 输出系统欢迎界面
System.out.println("*************************************");
System.out.println("* *");
System.out.println("* 欢迎使用学生管理系统 *");
System.out.println("* *");
System.out.println("*************************************");
while(true){
while(!isLogin){
//2.2 管理员登录界面
System.out.println("\n请选择操作:0-登录系统 1-关闭系统");
String input = sc.nextLine();
if("1".equals(input)){
//return;
System.exit(0);
}else if("0".equals(input)){
//登录操作
System.out.print("请输入账号:");
adminName = sc.nextLine();
System.out.print("请输入密码:");
adminPassword = sc.nextLine();
while(!"admin".equals(adminName) || !"123456".equals(adminPassword)){
System.out.println("您的账号或密码有误。请重新输入!\n");
System.out.print("请输入账号:");
adminName = sc.nextLine();
System.out.print("请输入密码:");
adminPassword = sc.nextLine();
}
isLogin = true;
/*
if("admin".equals(adminName) && "123456".equals(adminPassword)){
isLogin = true;
}else{
System.out.println("您的账号或密码有误。请重新输入!");
}*/
}else{
System.out.println("您的选择有误。请重新选择!\n");
}
if(isLogin)
System.out.println("\n欢迎您," + adminName);
}//end 登录while
//2.3 如果登录成功,输出操作菜单供管理员选择
System.out.println();
System.out.println("\n请选择相应的操作菜单项:");
System.out.println(" 0-添加新的学生信息");
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.print("选择项:");
String menuItem = sc.nextLine();
//2.4 根据选择的菜单项,执行相应的学生信息管理
switch(menuItem){
case "0": //增加
if(count == stus.length){
System.out.println("本班已满,请另谋高就.");
}else{
System.out.print("请输入学生学号:");
String stuId = sc.nextLine();
System.out.print("请输入学生姓名:");
String stuName = sc.nextLine();
//?是否要进行非空检测?
//创建一个Student类型的实例对象
Student stu = new Student();
//然后将输入的该生信息填充到该实例对象的字段中
stu.stuId = stuId;
stu.stuName = stuName;
//ids[count] = stuId;
//names[count] = stuName;
stus[count] = stu;
count++;
}
break;
case "1":
System.out.print("请指定要删除的学生学号:");
String stuId3 = sc.nextLine();
boolean delete = false;
for(int i=0;i<count;i++){
Student everyone = stus[i];
String everyoneid = everyone.stuId;
if(everyoneid.equals(stuId3)){
if(i!=count-1){ //如果要删除的元素不是数组中最后一个
//移位删除
for(int j=i;j<count-1;j++){
stus[j] = stus[j+1];
}
}
count--;
delete = true;
break;
}
}
if(delete){
//System.out.println("删除成功!");
// javax.swing.JOptionPane.showMessageDialog(null,"删除成功!");
System.out.println("删除成功");
System.out.println("查无此人!");
}
break;
case "2":
System.out.print("请指定要修改的学生学号:");
String stuId2 = sc.nextLine();
boolean update = false;
for(int i=0;i<count;i++){
Student everyone2 = stus[i];
String everyoneid2 = everyone2.stuId;
if(everyoneid2.equals(stuId2)){ //当找到要修改的学生时
System.out.print("请输入新的姓名信息:");
stus[i].stuName = sc.nextLine();
update = true;
break;
}
}
if(update){
System.out.println("修改成功!");
}else{
System.out.println("查无此人!");
}
break;
case "3":
System.out.print("请指定要查看的学生学号:");
String stuId = sc.nextLine();
boolean find = false;
for(int i=0;i<count;i++){
Student everyone3 = stus[i];
String everyoneid3 = everyone3.stuId;
if(everyoneid3.equals(stuId)){
System.out.println("学号:" + stus[i].stuId + ", 姓名:" + stus[i].stuName);
find = true;
break;
}
}
if(!find){System.out.println("查无此人!");}
break;
case "4":
if(count == 0){
System.out.println("目前班级人数为0。");
}else{
for(int i=0;i<count;i++){
System.out.println("学号:" + stus[i].stuId + ", 姓名:" + stus[i].stuName);
}
}
break;
case "5":
isLogin = false; //设为未登录状态
break;
case "6":
System.out.println("您确定要退出本系统? 确定(Y) 取消(N)");
String confirm = sc.nextLine();
if("Y".equals(confirm) || "y".equals(confirm)){
System.out.println("欢迎下次光临!");
System.exit(0);
}
break;
default:
break;
}//end switch
}//end while