上午
学生管理系统
/StuManage/学生管理系统函数
public class StuManage {
//该类定义所有相关的学生管理系统的函数方法
//注册功能
User[] users= new User[10];
Stu[] stus= new Stu[10];
//创建专门用于存储user对象的数组为了能够使该数组不会在每次调用注册功能的时候初始化。为了能够使登录函数使用
Scanner sc= new Scanner(System.in);
//注册功能
public void zhuce(){
System.out.println("请您输入注册的账户:");
String username = sc.next();
System.out.println("请您输入注册的密码:");
String password = sc.next();
//把输入的账号和密码封装在一个User对象中
User user = new User();
user.username=username;
user.password=password;
//把User对象存在数组中
//创建专门用于存储user对象的数组
for (int i = 0; i < users.length; i++) {
if (users[i] == null) {
if (username!=username) {
users[i] = user;
System.out.println("注册成功");
return;
}else {
System.out.println("注册失败");
}
return;
}
System.out.println("注册失败");
}
}
//登录功能
public void login(){
System.out.println("请您输入登录账号");
String username =sc.next();
System.out.println("请您输入登录密码");
String password =sc.next();
for (int i = 0; i <users.length ; i++) {
if (users[i]!=null&&users[i].username.equals(username)&&users[i].password.equals(password)){
System.out.println("登录成功");
menu2();
}
else if (users[i].username.equals(username)&&users[i].password!=password) {
System.out.println("登陆失败,您的密码错误!");
}
else if (users[i].username!=username&&users[i].password.equals(password)){
System.out.println("登陆失败,您的账号不存在!");
}
}
}
//添加功能
//添加学生信息
public void add(){
System.out.println("请您输入姓名:");
String name =sc.next();
System.out.println("请您输入电话:");
String phone =sc.next();
Stu stu =new Stu();
stu.name=name;
stu.phone=phone;
for (int i = 0; i <stus.length ; i++) {
if (stus[i]==null){
stus[i]=stu;
System.out.println("添加成功!");
return;
}
}
System.out.println("添加失败!");