首页 > 代码库 > 上了10天的基本课程写下的代码,博你一笑
上了10天的基本课程写下的代码,博你一笑
import java.util.Scanner;
public class GradeManage1 {
// 信息:用户名、密码、学生姓名、学号、分数。各一个数组(每个信息的数组下标相同)
/**
* users--用户名 passwords--密码 names--姓名 numbers--学号 grades--分数 problems--反馈问题
* (目前已知bug:反馈姓名和成绩分别一次问题,会把第一次反馈的给替换掉) 还未实现功能:反馈问题处理掉以后消除反馈
* (后期扩展功能:注册账号数达上限,反馈至管理员处,管理员可以增加数组个数)
*/
public static void main(String[] args) {
System.out.println("**欢迎来到学生信息管理系统**");
String[] users = new String[3];
String[] passwords = new String[3];
String[] names = new String[3];
int[] numbers = new int[3];
int[] grades = new int[3];
String[] problems = new String[3];
users[0] = "admin";
passwords[0] = "123456";
names[0] = "管理员";
menu(users, passwords, names, numbers, grades, problems);
}
/**
* 登录主页
*/
public static void menu(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("【主菜单】请选择功能:");
System.out.println("1.注册");
System.out.println("2.登录:");
System.out.println("3.管理员入口:");
System.out.println("4.退出");
String input = s1.nextLine();
switch (input) {
case "1":
regist(users, passwords, names, numbers, grades, problems);
break;
case "2":
login(users, passwords, names, numbers, grades, problems);
break;
case "3":
adminInput(users, passwords, names, numbers, grades, problems);
break;
case "4":
System.out.println("***欢迎使用,再见!***");
System.exit(0);
default:
System.out.println("输入有误,请重新输入");
menu(users, passwords, names, numbers, grades, problems);
}
}
/**
* <学生>注册界面
*/
public static void regist(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("请分别填写以下信息【回车确定】");
System.out.println("1.用户名:");
System.out.println("2.密码:");
System.out.println("3.姓名:");
String user = s1.nextLine();
String password = s1.nextLine();
String name = s1.nextLine();
int k = -1;
for (int i = 0; i < users.length; i++) {
if (users[i] == null) {
users[i] = user;
passwords[i] = password;
names[i] = name;
numbers[i] = (int) (Math.random() * 10 - 1);
// 随机生成一个1-9的数字赋给学号numbers数组里
System.out.println("注册成功,请登录");
menu(users, passwords, names, numbers, grades, problems);
break;
} else if (users[i].equals(user)) {
System.out.println("该用户名已被使用!");
regist(users, passwords, names, numbers, grades, problems);
} else if (i == users.length - 1) {
k = i;
}
}
if (k == users.length - 1) {
Scanner s2 = new Scanner(System.in);
System.out.println("允许注册人数已满,请联系管理员清理或增加容量");
System.out.println("是否反馈?Y/N?\n当然你也可以按下其他任意键切断电源0.0");
String choice = s2.nextLine();
choice = choice.toUpperCase();
if (choice.equals("Y")) {
problems[0] = "系统注册人数已满,请增加容量!";
menu(users, passwords, names, numbers, grades, problems);
} else if (choice.equals("N")) {
menu(users, passwords, names, numbers, grades, problems);
} else {
System.exit(0);
}
}
}
/**
* <学生>登录界面
*/
public static void login(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("用户名:");
String user = s1.nextLine();
Scanner s2 = new Scanner(System.in);
System.out.println("密码:");
String password = s2.nextLine();
int rank = -1;
for (int i = 0; i < users.length; i++) {
if (users[i].equals(user) && passwords[i].equals(password)) {
System.out.println("登录成功!欢迎你 " + names[i]);
rank = i;
// rank 用来表示该同学的数组下标
function(users, passwords, names, numbers, grades, problems, rank);
break;
} else if (i == users.length - 1) {
// 对数组中数据进行索引,且在最后一次查找中输出结果
System.out.println("用户名或密码错误,请尝试注册或重新登录");
menu(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <学生>登录功能选择板块
*/
public static void function(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems, int rank) {
Scanner s1 = new Scanner(System.in);
System.out.println("功能选择:");
System.out.println("1.查询成绩");
System.out.println("2.查询学号");
System.out.println("3.修改密码");
System.out.println("4.个人信息错误反馈");
System.out.println("5.注销");
String choice = s1.nextLine();
switch (choice) {
case "1":
System.out.println("您的成绩为:" + grades[rank]);
function(users, passwords, names, numbers, grades, problems, rank);
break;
case "2":
System.out.println("您的学号为:J133-" + numbers[rank]);
function(users, passwords, names, numbers, grades, problems, rank);
break;
case "3":
Scanner s2 = new Scanner(System.in);
System.out.println("请输入新密码:");
String newpsd = s2.nextLine();
passwords[rank] = newpsd;
System.out.println("修改密码成功!");
function(users, passwords, names, numbers, grades, problems, rank);
break;
case "4":
takeProblems(users, passwords, names, numbers, grades, problems, rank);
function(users, passwords, names, numbers, grades, problems, rank);
break;
case "5":
menu(users, passwords, names, numbers, grades, problems);
break;
default:
System.out.println("输入有误,请重新输入!");
function(users, passwords, names, numbers, grades, problems, rank);
}
}
/**
* <学生>(登录)反馈问题
*/
public static void takeProblems(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems, int rank) {
Scanner s1 = new Scanner(System.in);
System.out.println("【学生问题反馈】:");
System.out.println("请选择异常信息:");
System.out.println("1.姓名有误");
System.out.println("2.成绩有误");
System.out.println("3.返回上一级菜单");
String choice = s1.nextLine();
switch (choice) {
case "1":
Scanner s2 = new Scanner(System.in);
System.out.println("请输入正确的姓名:");
String tureName = s2.nextLine();
problems[rank] = "用户名为" + users[rank] + "的同学反馈姓名为:" + tureName;
// += 是防止如果该同学成绩姓名都有误时,数据被替换,这里的+为连接符
System.out.println("已向管理员反馈,等待管理员修改");
takeProblems(users, passwords, names, numbers, grades, problems, rank);
break;
case "2":
Scanner s3 = new Scanner(System.in);
System.out.println("请输入正确的成绩:");
int tureGrade = s3.nextInt();
problems[rank] = "用户名为" + users[rank] + "的同学反馈姓名为:" + tureGrade;
System.out.println("已向管理员反馈,等待管理员修改");
takeProblems(users, passwords, names, numbers, grades, problems, rank);
break;
case "3":
function(users, passwords, names, numbers, grades, problems, rank);
break;
default:
System.out.println("输入有误,请重新输入!");
takeProblems(users, passwords, names, numbers, grades, problems, rank);
}
}
/**
* <管理员>登录输入确认
*/
public static void adminInput(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("管理员账号:");
String inputUser = s1.nextLine();
Scanner s2 = new Scanner(System.in);
System.out.println("管理员密码:");
String inputPsd = s2.nextLine();
if (inputUser.equals(users[0]) && inputPsd.equals(passwords[0])) {
System.out.println("登录成功!欢迎管理员");
adminMenu(users, passwords, names, numbers, grades, problems);
} else {
System.out.println("账号或密码错误!");
menu(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>登录菜单界面
*/
public static void adminMenu(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("【选择功能】:");
System.out.println("1.新增学生信息");
System.out.println("2.查看修改学生信息");
System.out.println("3.查看问题反馈情况");
System.out.println("4.修改密码");
System.out.println("5.注销");
String input = s1.nextLine();
switch (input) {
case "1":
newInformation(users, passwords, names, numbers, grades, problems);
break;
case "2":
findFix(users, passwords, names, numbers, grades, problems);
break;
case "3":
Problems(users, passwords, names, numbers, grades, problems);
break;
case "4":
newPsd(users, passwords, names, numbers, grades, problems);
break;
case "5":
menu(users, passwords, names, numbers, grades, problems);
break;
}
}
/**
* <管理员>新增学生信息
*/
public static void newInformation(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("【新增学生信息】:");
System.out.println("请分别填写以下信息【回车确定】");
System.out.println("1.用户名:");
System.out.println("2.密码:");
System.out.println("3.姓名:");
System.out.println("4.分数:");
String user = s1.nextLine();
String password = s1.nextLine();
String name = s1.nextLine();
int grade = s1.nextInt();
for (int i = 0; i < users.length; i++) {
if (users[i] == null) {
// 数组的值为null表示没有被注册
users[i] = user;
passwords[i] = password;
names[i] = name;
grades[i] = grade;
System.out.println("该学生信息已经新增完毕!");
System.out.print("用户名:" + users[i] + "密码:" + passwords[i] + "\n姓名:" + names[i] + "分数" + grades[i]);
Scanner s2 = new Scanner(System.in);
System.out.println("继续新增?Y/N?");
System.out.println("输入其他会爆炸!");
String choice = s2.nextLine();
choice = choice.toUpperCase();
if (choice.equals("Y")) {
newInformation(users, passwords, names, numbers, grades, problems);
} else if (choice.equals("N")) {
adminMenu(users, passwords, names, numbers, grades, problems);
} else {
System.out.println("骗你的!");
adminMenu(users, passwords, names, numbers, grades, problems);
}
break;
} else if (i == users.length - 1) {
// 索引完全
System.out.println("学生存储量已满,需要扩大存储容量!");
}
}
}
/**
* <管理员>查看修改学生信息
*/
public static void findFix(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("【查看修改学生信息】:");
System.out.println("1.输入用户名查找");
System.out.println("2.输入姓名查找:");
System.out.println("3.输入学号查找:");
System.out.println("4.返回上一级菜单:");
String input = s1.nextLine();
switch (input) {
case "1":
find_User(users, passwords, names, numbers, grades, problems);
break;
case "2":
find_Name(users, passwords, names, numbers, grades, problems);
break;
case "3":
find_Number(users, passwords, names, numbers, grades, problems);
break;
case "4":
adminMenu(users, passwords, names, numbers, grades, problems);
break;
default:
System.out.println("输入有误,请重新输入");
findFix(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>(查找信息)用户名查找
*/
public static void find_User(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("用户名:");
String user = s1.nextLine();
for (int i = 0; i < users.length; i++) {
if (users[i].equals(user)) {
System.out.println("用户" + users[i] + "的信息如下");
System.out.println("【如需修改请输入前方数字,返回请输入N】");
System.out.println("PS:用户名、学号不能修改");
System.out.println("学号:" + numbers[i]);
System.out.println("1.姓名:" + names[i]);
System.out.println("2.成绩:" + grades[i]);
fix_User(users, passwords, names, numbers, grades, problems, i);
findFix(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <管理员>(用户名查找)修改信息
*/
public static void fix_User(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems, int i) {
Scanner s1 = new Scanner(System.in);
String choice = s1.nextLine();
choice = choice.toUpperCase();
switch (choice) {
case "1":
System.out.println("修改姓名为:");
Scanner s2 = new Scanner(System.in);
String name = s2.nextLine();
names[i] = name;
System.out.println("修改成功!");
break;
case "2":
System.out.println("修改成绩为:");
Scanner s3 = new Scanner(System.in);
int grade = s3.nextInt();
grades[i] = grade;
System.out.println("修改成功!");
break;
case "N":
break;
default:
System.out.println("输入有误,请重新输入");
find_User(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>(查找信息)姓名查找
*/
public static void find_Name(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("姓名:");
String name = s1.nextLine();
for (int i = 0; i < names.length; i++) {
if (names[i].equals(name)) {
System.out.println("姓名" + names[i] + "的信息如下");
System.out.println("【如需修改请输入前方数字,返回请输入N】");
System.out.println("PS:用户名、学号不能修改");
System.out.println("学号:" + numbers[i]);
System.out.println("用户名:" + users[i]);
System.out.println("1.成绩:" + grades[i]);
fix_Name(users, passwords, names, numbers, grades, problems, i);
findFix(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <管理员>(姓名查找)修改信息
*/
public static void fix_Name(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems, int i) {
Scanner s1 = new Scanner(System.in);
String choice = s1.nextLine();
choice = choice.toUpperCase();
switch (choice) {
case "1":
System.out.println("修改成绩为:");
Scanner s2 = new Scanner(System.in);
int grade = s2.nextInt();
grades[i] = grade;
System.out.println("修改成功!");
break;
case "N":
break;
default:
System.out.println("输入有误,请重新输入");
find_Name(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>(查找信息)学号查找
*/
public static void find_Number(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
Scanner s1 = new Scanner(System.in);
System.out.println("学号:");
int number = s1.nextInt();
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] == number) {
System.out.println("学号" + numbers[i] + "的信息如下");
System.out.println("【如需修改请输入前方数字,返回请输入N】");
System.out.println("PS:用户名、学号不能修改");
System.out.println("用户名:" + users[i]);
System.out.println("1.姓名:" + names[i]);
System.out.println("2.成绩:" + grades[i]);
fix_Number(users, passwords, names, numbers, grades, problems, i);
findFix(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <管理员>(用户名查找)修改信息
*/
public static void fix_Number(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems, int i) {
Scanner s1 = new Scanner(System.in);
String choice = s1.nextLine();
choice = choice.toUpperCase();
switch (choice) {
case "1":
System.out.println("修改姓名为:");
Scanner s2 = new Scanner(System.in);
String name = s2.nextLine();
names[i] = name;
System.out.println("修改成功!");
break;
case "2":
System.out.println("修改成绩为:");
Scanner s3 = new Scanner(System.in);
int grade = s3.nextInt();
grades[i] = grade;
System.out.println("修改成功!");
break;
case "N":
break;
default:
System.out.println("输入有误,请重新输入");
find_Number(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>查看问题反馈情况
*/
public static void Problems(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
System.out.println("有以下问题反馈:");
for (int i = 0; i < users.length; i++) {
if (problems[i] != null) {
System.out.println(problems[i]);
} else if (problems[i] == null && i == users.length - 1) {
System.out.println("暂无任何反馈信息");
adminMenu(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <管理员>修改密码
*/
public static void newPsd(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems) {
System.out.println("【请选择】:");
Scanner s1 = new Scanner(System.in);
System.out.println("1.学生密码重置");
System.out.println("2.管理员密码修改:");
System.out.println("3.返回");
String input = s1.nextLine();
switch (input) {
case "1":
studentPsd(users, passwords, names, numbers, grades, problems);
break;
case "2":
adminPsd(users, passwords, names, numbers, grades, problems);
break;
case "3":
adminMenu(users, passwords, names, numbers, grades, problems);
break;
default:
System.out.println("输入有误,请重新输入");
newPsd(users, passwords, names, numbers, grades, problems);
}
}
/**
* <管理员>(修改密码)学生密码重置
*/
public static void studentPsd(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems){
System.out.println("输入需要重置密码的用户名:");
Scanner s1 = new Scanner(System.in);
String user = s1.nextLine();
for(int i = 0; i < users.length; i++){
if(users[i] != null && user.equals(users[i])){
System.out.println("新密码:");
Scanner s2 = new Scanner(System.in);
String password = s2.nextLine();
passwords[i] = password;
System.out.println("密码已经重置!");
newPsd(users, passwords, names, numbers, grades, problems);
break;
}else if(i == users.length - 1){
System.out.println("该用户名不存在!");
newPsd(users, passwords, names, numbers, grades, problems);
}
}
}
/**
* <管理员>(修改密码)管理员密码修改
*/
public static void adminPsd(String[] users, String[] passwords, String[] names, int[] numbers, int[] grades,
String[] problems){
System.out.println("输入新密码:");
Scanner s1 = new Scanner(System.in);
String password = s1.nextLine();
passwords[0] = password;
System.out.println("密码修改成功");
newPsd(users, passwords, names, numbers, grades, problems);
}
}
上了10天的基本课程写下的代码,博你一笑