package day6HomeWork;
/*
尽量做(尽量做),简易成绩管理系统:分2大块功能
1、实现一个菜单包括:A注册 注册一个管理员账户:B登录 通过注册的账户登录系统
C退出 退出整个程序
2、实现一个菜单:A新增学生分数信息 循环新增学生的姓名与分数信息
B修改学生分数信息 通过学生的姓名修改一个学生的分数
C删除学生分数信息 通过学生的姓名删除一个学生的姓名与分数
D查询学生信息 查询功能看第3小点
E返回上级菜单
3、查询学生信息中实现一个小菜单:A查询学生分数 通过一个学生姓名查询一个学生分数
B查询所有学生分数 查询所有学生的分数
*/
import javax.swing.JOptionPane;
public class studentManageSystem {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] user = new String[10];
int[] password = new int[10];
while (true){
JOptionPane.showMessageDialog(null, "A:注册\nB:登录\nC:退出\n");
String str = JOptionPane.showInputDialog(null,"请选择菜单项(A-C):");
char opt = str.toCharArray()[0];
switch(opt){
case ‘A‘:
register(user,password);
break;
case ‘B‘:
login(user,password);
break;
case ‘C‘:
JOptionPane.showMessageDialog(null, "退出系统");
System.exit(-1);//退出while死循环
break;
default:
JOptionPane.showMessageDialog(null,"操作错误,请重新输入");
break;
}
}
}
//注册
static void register(String[] user,int[] password){
String username = JOptionPane.showInputDialog(null,"请输入要注册的用户名:");
int pwd = Integer.parseInt(JOptionPane.showInputDialog(null,"请输入要注册的用户名密码:"));
for (int i=0; i<user.length; i++){
if (user[i] == null){
user[i] = username;
password[i] = pwd;
break;
}
}
}
//登录
static void login(String[] user,int[] password){
String username = JOptionPane.showInputDialog(null,"请输入用户名:");
int pwd = Integer.parseInt(JOptionPane.showInputDialog(null,"请输入密码:"));
boolean flag = false;
for (int i=0; i<user.length; i++){
if (username.equals(user[i]) && pwd == password[i]){
JOptionPane.showMessageDialog(null,"登陆成功");
menue(username);
flag = true;
break;
}
}
if (flag == false)
JOptionPane.showMessageDialog(null, "登录失败");
}
//学生菜单
static void menue(String user){
String[] studentName = new String[10];
int[] studentScore = new int[10];
boolean flag = false;
while (true){
JOptionPane.showMessageDialog(null,"你好"+user+",欢迎进入学生管理系统:\n"
+ "A:新增学生成绩\nB:修改学生成绩\nC:删除学生成绩\n"
+ "D:查询学生成绩\nE:返回上级菜单\n");
String str = JOptionPane.showInputDialog(null,"请选择菜单:");
char opt = str.toCharArray()[0];
switch(opt){
case ‘A‘:
addStudentScore(studentName,studentScore);
break;
case ‘B‘:
updateStudentScore(studentName,studentScore);
break;
case ‘C‘:
deleteStudentScore(studentName,studentScore);
break;
case ‘D‘:
queryStudentScore(studentName,studentScore);
break;
case ‘E‘:
flag = true;
break;
default:
JOptionPane.showMessageDialog(null, "输入有误,请重新选择");
break;
}
if (flag == true)
break;
}
}
//新增学生成绩
static void addStudentScore(String[] studentName,int[] studentScore){
for (int i=0; i<studentName.length; i++){
String name = JOptionPane.showInputDialog(null,"请输入学生姓名:");
studentName[i] = name;
studentScore[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"请输入学生成绩:"));
}
}
//修改学生成绩
static void updateStudentScore(String[] studentName,int[] studentScore){
String name = JOptionPane.showInputDialog(null,"请输入要修改分数的学生姓名:");
for (int i=0; i<studentScore.length; i++){
if (name.equals(studentName[i]))
studentScore[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"请输入要修改分数的学生成绩:"));
}
}
//删除学生成绩
static void deleteStudentScore(String[] studentName,int[] studentScore){
String name = JOptionPane.showInputDialog(null,"请输入要删除分数的学生姓名:");
//boolean flag = false;
for (int i=0; i<studentName.length; i++){
if (studentName.length-1 == i){//遇到最后一个元素就退出
studentName[i] = null;
studentScore[i] = 0;
break;
}
if (name.equals(studentName[i])){
//flag = true;
studentName[i] = studentName[i+1];
studentScore[i] = studentScore[i+1];
}
}
for (int i=0; i<studentName.length; i++)
JOptionPane.showMessageDialog(null,"学生姓名:"+studentName[i]+"\n学生成绩:"+studentScore[i]);
}
//查询学生成绩
static void queryStudentScore(String[] studentName,int[] studentScore){
boolean flag = false;
while (true){
JOptionPane.showMessageDialog(null, "A:查询单个学生信息\nB:查询所有学生信息\n"
+ "C:返回上级菜单");
char opt = JOptionPane.showInputDialog(null,"请选择菜单:").toCharArray()[0];
switch(opt){
case ‘A‘:
querySingleStudentScore(studentName,studentScore);
break;
case ‘B‘:
queryAllStudentScore(studentName,studentScore);
break;
case ‘C‘:
flag = true;
break;
default:
JOptionPane.showMessageDialog(null,"输入有误,请重新输入");
break;
}
if (flag == true)
break;
}
}
//查询单个学生的成绩
static void querySingleStudentScore(String[] studentName,int[] studentScore){
String name = JOptionPane.showInputDialog(null,"请输入一位学生姓名:");
boolean flag = false;
for (int i=0; i<studentName.length; i++){
if (name.equals(studentName[i])){
JOptionPane.showMessageDialog(null,"学生:"+studentName[i]+"的成绩为:"+studentScore[i]);
flag = true;
break;
}
}
if (flag == false)
JOptionPane.showMessageDialog(null,"该学生不存在");
}
static void queryAllStudentScore(String[] studentName,int[] studentScore){//查询所有学生的成绩
for (int i=0; i<studentName.length; i++)
JOptionPane.showMessageDialog(null,"学生:"+studentName[i]+"的成绩为:"+studentScore[i]);
}
}
原文:http://www.cnblogs.com/lyrand/p/6503142.html