上了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);
}
}

时间: 2024-10-19 19:47:17

上了10天的基本课程写下的代码,博你一笑的相关文章

不写1行代码,在Mac上体验ASP.NET 5的最简单方法

昨天微软发布了ASP.NET 5 beta2(详见ASP.NET 5 Beta2 发布),对ASP.NET 5的好奇心又被激发了. 今天下午在Mac OS X上体验了一下ASP.NET 5 beta2,而且借助Yeoman generators for ASP.NET 5,可以不用写1行代码,连project.json都不用写.有一种Mac下用Visual Studio的感觉. 下面分享一下实际的操作步骤: 1. 安装OS X的包包管理器:Homebrew 2. 将ASP.NET 5在githu

专心10年,写ASP.NET代码开始,从0到拥有5系

工作到现在,几乎就没离开过这里,写这篇文章也是给自己这10年做个总结,也希望能给选择了程序员这个职业的朋友,带来一些激励与感悟,写这文章又不想影响到自己的工作与生活,所以专门注册了一个马甲帐号请谅解,我也是园子的常客,有写过很多博文. 起点高低不会左右你的人生在这个职业里.我的同事与朋友里,好像我的起点还真是挺低的,高中辍学,妈妈看了我这样白上了10年学,到工地打工浪费了,拿出了家里仅有的5000元报了一个职业学校,学了一年的计算机技术,PHOTOSHOP,网页制作三剑客,还有后来ASP语言.在

iOS-开发者能用上的 10 个 Xcode 插件

6 iOS 开发者能用上的 10 个 Xcode 插件 7 8 2014/12/08 · iOS, 工具与资源 · iOS, Xcode 9 分享到: 22 10 本文由 伯乐在线 - 邢敏 翻译,黄利民 校稿.未经许可,禁止转载! 11 英文出处:code.tutsplus.com.欢迎加入翻译组. 12 1. XcodeColors:给 Xcode 控制台添加颜色 13 2. XToDo:这个插件不仅高亮 TODO. FIXME. ???,还高亮 !!! 注释 14 3. Backlight

SQL点滴10—使用with语句来写一个稍微复杂sql语句,附加和子查询的性能对比

原文:SQL点滴10-使用with语句来写一个稍微复杂sql语句,附加和子查询的性能对比 今天偶尔看到sql中也有with关键字,好歹也写了几年的sql语句,居然第一次接触,无知啊.看了一位博主的文章,自己添加了一些内容,做了简单的总结,这个语句还是第一次见到,学习了.我从简单到复杂地写,希望高手们不要见笑.下面的sql语句设计到三个表,表的内容我用txt文件复制进去,这里不妨使用上一个随笔介绍的建立端到端的package的方法将这些表导入到数据库中,具体的就不说了. 从这里下载文件employ

世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299 输出例子: 7

这是小米2015年暑假实习生第一道笔试题,其实不难,主要用到移位操作和或运算符就可以搞定,具体代码如下: /*世界上有10种人,一种懂二进制,一种不懂.那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么? 输入例子: 1999 2299 输出例子: 7 */ #include<stdio.h> int countBitDiff(int m, int n) { int data=1; int a,b; int count=0; for(int i=0;i<31;i+

python小练习,打出1-100之间的所有偶数,设计一个函数,在桌面上创建10个文件,并以数字命名,复利计算函数

练习一:打出1-100之间的所有偶数 def even_print(): for i in range(1,101): if i % 2 == 0: print (i) even_print() 练习二:设计一个函数,在桌面上创建10个文件,并以数字命名 def text_creation(): path = 'C:/Users/Administrator/Desktop' for name in range (1,11): with open(path + str(name) + '.txt'

1418作业(8)多线程 开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID 在屏幕上打印10遍

/****************************************************************************** *题目: 编写一个程序,开启3个线程,这3个线程的ID分别为A.B.C,每个线程将自己的ID * 在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示:如:ABCABC-依次递推. ******************************************************************************

Mysql在字符串类型的日期上加上10分钟并和现在的日期做比较

SELECT id FROM tran WHERE state = 'F' AND TIMESTAMPDIFF(SECOND,DATE_ADD(create_date,INTERVAL 10 DAY_MINUTE),"2014-06-18 10:30:29")>0 如果create_date加10分钟大于等于当前的时间("2014-06-18 10:30:29") 那么就会查到数据, 如果小于那么就查不到数据 Mysql在字符串类型的日期上加上10分钟并和现在

java写的迷宫代码

迷宫代码:截图如下:package com.zxl.maze; /* * 抽象类表示选择不同的算法*/ public abstract class AbstractMap { /* * 得到数据*/ public abstract boolean[][] getData(int m,int n); /* * 重置*/ public abstract void reset(int m,int n); } package com.zxl.maze; /* *深度优先,生成迷宫*/ import ja