学生信息管理系统Java基础版无数据库Word格式.docx
《学生信息管理系统Java基础版无数据库Word格式.docx》由会员分享,可在线阅读,更多相关《学生信息管理系统Java基础版无数据库Word格式.docx(17页珍藏版)》请在冰豆网上搜索。
"
}
//打印二级菜单
publicstaticvoidprintSecondMenu()
//输出二级菜单
1.查看学生信息"
2.添加学生信息"
3.修改学生信息"
4.查询学生信息"
5.删除学生信息"
6.退出"
//打印三级菜单
publicstaticvoidprintThirdMenu()
//输出第三级菜单
1.按学生学号查询"
2.按学生姓名查询"
3.按学生年龄查询"
4.按学生职务查询"
5.退出"
//定义初始化数据
publicstaticvoidinitStudent()
String[]s1={"
s001"
"
张三"
21"
学生"
};
String[]s2={"
s002"
李四"
22"
班长"
String[]s3={"
s003"
王五"
23"
干部"
String[]s4={"
s004"
张伟"
28"
旁听"
students[0]=s1;
students[1]=s2;
students[2]=s3;
students[3]=s4;
//查看学生信息
publicstaticvoidlookStudent()
for(inti=0;
i<
count;
i++)
{
for(intj=0;
j<
students[i].length;
j++)
{
System.out.print(students[i][j]+"
\t"
}
System.out.println();
}
//添加学生信息
publicstaticvoidaddStudent()
Scannerscanner=newScanner(System.in);
请输入新的学号:
StringstuNo2=scanner.nextLine();
scanner=newScanner(System.in);
请输入新的姓名:
StringstuName2=scanner.nextLine();
请输入新的年龄:
StringstuAge2=scanner.nextLine();
请输入新的职务:
StringstuTitle2=scanner.nextLine();
//将用户输入的新学生信息构造一个新的String数组
String[]tmpStu2={stuNo2,stuName2,stuAge2,stuTitle2};
//将此新学生添加到二维数组中
students[count]=tmpStu2;
count++;
//修改学生信息
publicstaticvoidmodifyStudent()
//按学号查找对应的学生信息
请输入需要修改的学生的学号:
Scannerscanner=newScanner(System.in);
StringchangeNo=scanner.nextLine();
intchangeCount=0;
//标记,作为所找学生的标记
booleanchangeFlag=false;
//标记,决定是否修改
if(students[i][0].equals(changeNo))
System.out.println("
找到,信息如下:
for(intj=0;
{
System.out.print(students[i][j]+"
}
changeCount=i;
changeFlag=true;
break;
}
//修改
if(changeFlag)
scanner=newScanner(System.in);
System.out.print("
StringstuNo3=scanner.nextLine();
StringstuName3=scanner.nextLine();
StringstuAge3=scanner.nextLine();
StringstuTitle3=scanner.nextLine();
String[]tmpStu3={stuNo3,stuName3,stuAge3,stuTitle3};
students[changeCount]=tmpStu3;
//显示修改后的学生信息
System.out.println("
修改后的学生信息:
for(inti=0;
lookStudent();
else
没找到!
!
请核实输入数据!
//查询学生信息
//按学生学号查询
publicstaticvoidqueryStudentNo()
请输入需要查询的学生的学号:
StringfindNo=scanner.nextLine();
booleanfindFlag1=true;
//标记,用来显示是否找到
if(students[i][0].equals(findNo))
findFlag1=false;
System.out.println();
if(findFlag1)
抱歉,没有此人!
//按学生姓名查询
publicstaticvoidqueryStudentName()
请输入需要查询的学生的姓名:
StringfindName=scanner.nextLine();
booleanfindFlag2=true;
//标记,用来显示是否找到信息
if(students[i][1].equals(findName))
findFlag2=false;
if(i==count)
if(findFlag2)
//按学生年龄查询
publicstaticvoidqueryStudentAge()
请输入需要查询的学生的年龄:
StringfindAge=scanner.nextLine();
booleanfindFlag3=true;
if(students[i][2].equals(findAge))
findFlag3=false;
if(findFlag3)
//按学生职务查询
publicstaticvoidqueryStudentTitle()
请输入需要查询的学生的职务:
StringfindTitle=scanner.nextLine();
booleanfindFlag4=true;
if(students[i][3].equals(findTitle))
findFlag4=false;
if(findFlag4)
}
//删除学生信息
publicstaticvoiddeleteStudent()
请输入需要删除的学生的学号:
StringdeleteNo=scanner.nextLine();
intdeleteCount=0;
booleandeleteFlag=false;
//标记,决定是否删除
if(students[i][0].equals(deleteNo))
deleteCount=i;
//
deleteFlag=true;
//删除
if(deleteFlag)
for(intj=deleteCount+1;
students[count].length;
students[deleteCount]=students[j];
deleteCount++;
count--;
//显示删除后的学生信息
删除后的学生信息:
//验证登录信息
publicstaticbooleanverifyStudent()
booleanverifyFlag=false;
请输入用户名:
StringuserName=scanner.nextLine();
请输入密码:
Stringpassword=scanner.nextLine();
if("
2010031"
.equals(userName)&
&
.equals(password))
verifyFlag=true;
returnverifyFlag;
publicstaticvoidmain(String[]args){//main函数
initStudent();
//初始化学生信息数组
booleanfirstFlag=false;
//标记位,据此决定是否退出一级菜单
while(true)
printFirstMenu();
//打印一级菜单
intfirstChoice=scanner.nextInt();
//接受用户的操作
switch(firstChoice)
case1:
booleanFlag1=verifyStudent();
//控制输出二级菜单(验证通过会输出)
if(Flag1)
booleansecondFlag=true;
//标记位,决定是否退出二级菜单
do{
printSecondMenu();
//打印二级菜单
scanner=newScanner(System.in);
intsecondChoice=scanner.nextInt();
switch(secondChoice)
{
case1:
//查看学生信息
lookStudent();
System.out.print("
输入0返回上一菜单——>
:
scanner=newScanner(System.in);
intback1=scanner.nextInt();
if(back1==0)
{
break;
}
break;
case2:
//添加学生信息
addStudent();
//显示添加后的学生信息
System.out.println("
添加后的学生信息:
for(inti=0;
for(intj=0;
{
System.out.print(students[i][j]+"
}
System.out.println();
intback2=scanner.nextInt();
if(back2==0)
case3:
//修改学生信息
modifyStudent();
intback3=scanner.nextInt();
if(back3==0)
case4:
//查询学生信息
booleanthirdFlag=f