class Student{
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;
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)){
//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;
}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 == stus.length){
System.out.println("本班已满,请另谋高就.");
}else{
System.out.print("请输入学生学号:");
String stuId = sc.nextLine();
System.out.print("请输入学生姓名:");
String stuName = sc.nextLine();
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,"删除成功!");
}else{
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;
}
}
}
}
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;
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)){
//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;
}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 == stus.length){
System.out.println("本班已满,请另谋高就.");
}else{
System.out.print("请输入学生学号:");
String stuId = sc.nextLine();
System.out.print("请输入学生姓名:");
String stuName = sc.nextLine();
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,"删除成功!");
}else{
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;
}
}
}
}