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];
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){
System.out.println("\n请选择操作:0-登录系统 1-关闭系统");
String input = sc.nextLine();
if("1".equals(input)){
System.exit(0);
}else if("0".equals(input)){
System.out.print("请输入账号:");
adminName = sc.nextLine();
System.out.print("请输入密码:");
adminPassword = sc.nextLine();
while(!"sunpandi".equals(adminName) || !"19940208".equals(adminPassword)){
System.out.println("您的账号或密码有误。请重新输入!\n");
System.out.print("请输入账号:");
adminName = sc.nextLine();
System.out.print("请输入密码:");
adminPassword = sc.nextLine();
}
isLogin = true;
}else{
System.out.println("您的选择有误。请重新选择!\n");
}
if(isLogin)
System.out.println("\n欢迎您," + adminName);
}
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();
switch(menuItem){
case "0":
if(count == names.length){
System.out.println("本班已满.");
}else{
System.out.print("请输入学生学号:");
String stuId = sc.nextLine();
System.out.print("请输入学生姓名:");
String stuName = sc.nextLine();
ids[count] = stuId;
names[count] = stuName;
count++;
}
break;
case "1":
System.out.print("请指定要删除的学生学号:");
String stuId3 = sc.nextLine();
boolean delete = false;
for(int i=0;i<count;i++){
if(ids[i].equals(stuId3)){
if(i!=count-1){ //如果要删除的元素不是数组中最后一个
for(int j=i;j<count-1;j++){
ids[j] = ids[j+1];
names[j] = names[j+1];
}
}
count--;
delete = true;
break;
}
}
if(delete){
//System.out.println("删除成功!");
javax.swing.JOptionPane.showMessageDialog(null,"删除成功!");
}else{
System.out.println("查无此人!");
}
break;
case "2":
System.out.print("请指定要修改的学生学号:");
String stuId2 = sc.nextLine();
boolean update = false;
for(int i=0;i<count;i++){
if(ids[i].equals(stuId2)){
System.out.print("请输入新的姓名信息:");
names[i] = 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++){
if(ids[i].equals(stuId)){
System.out.println("学号:" + ids[i] + ", 姓名:" + names[i]);
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("学号:" + ids[i] + ", 姓名:" + names[i]);
}
}
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;
}
}
}
}