您的位置:首页 > 编程语言 > Java开发

用java基础语言编写一个班级学生管理系统

2014-01-19 18:09 711 查看
/*需求:学生管理系统

功能:对学生的信息进行管理

1 添加学生信息;2 删除学生信息;3修改学生信息;4 查找指定学生信息;5 查找所有学生信息

涉及到的数据:

管理员:一个(账号-String;密码-String);

学生的信息:

学号:String;姓名:String;

存储数据:两个数组(学号;姓名)-String

*/


import java.util.Scanner;

class StuManager

{

public static void main(String[] args)

{

System.out.println("*********************");

System.out.println("* *");

System.out.println("* 学生信息管理系统 *");

System.out.println("* *");

System.out.println("*********************");

while(true){

System.out.println("1 登录系统; 2 结束系统");

Scanner input=new Scanner(System.in);

String log=input.nextLine();

String[] stuNames=new String[30];

String[] stuIds=new String[30];

int count=0;

if("1".equals(log)){

//登录界面

while(true){

boolean tag=true;

System.out.println("请输入账号");

String account =input.nextLine();

System.out.println("请输入密码");

String password =input.nextLine();

if("admin".equals(account)&&"123456".equals(password)){

//功能主界面

while(tag){

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("7-关闭系统");

System.out.println("*********************");

System.out.print("请选择功能:");

String function =input.nextLine();

switch(function){

case "1":

System.out.println("请输入学生学号:");

String stuId =input.nextLine();

System.out.println("请输入学生姓名:");

String stuName =input.nextLine();

stuNames[count]=stuName;

stuIds[count]=stuId;

count++;

break;

case "2":

boolean label=false;

System.out.println("请输入要删除的学生学号:");

String stuId1 =input.nextLine();

for(int i=0;i<count;i++){

if(stuIds[count-1].equals(stuId1)){

count--;

System.out.println("删除成功");

label=true;

}

else if(stuIds[i].equals(stuId1)){

for(int j=i;j<count-1;j++){

stuIds[j]=stuIds[j+1];

stuNames[j]=stuNames[j+1];

count--;

System.out.println("删除成功");

label=true;

}

}

}

if(!label){

System.out.println("查无此人,请重新操作");

}

break;

case "3":

boolean flag=false;

System.out.println("请输入要修改的学生学号:");

String stuId2 =input.nextLine();

for(int i=0;i<count;i++){

if(stuIds[i].equals(stuId2)){

System.out.println("请输入要修改后的学生学号:");

String stuName2 =input.nextLine();

stuNames[i]=stuName2;

flag=true;

}

}

if(!flag){

System.out.println("查无此人,请重新操作");

}

break;

case "4":

for(int i=0;i<count;i++){

System.out.println("学号:"+stuIds[i]+" 姓名:"+stuNames[i]);

}

break;

case "5":

boolean mark=false;

System.out.println("请输入要查找的学生学号:");

String stuId3 =input.nextLine();

for(int i=0;i<count;i++){

if(stuIds[i].equals(stuId3)){

System.out.println("学号:"+stuIds[i]+" 姓名:"+stuNames[i]);

mark=true;

}

}

if(!mark){

System.out.println("查无此人,请重新操作");

}

break;

case "6":

tag=false;

break;

case "7":

System.exit(0);

break;

default:

System.out.println("操作不正确,请重新操作");

break;

}

}

}

else{

System.out.println("账号或密码不正确,请重新输入");

}

}

}

else if("2".equals(log)){

return;

}

else{

System.out.println("操作不正确,请重新操作");

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: