package MyStudentManager;
import java.util.ArrayList;
import java.util.Scanner;
/*
* 学生管理系统的主类
* */
public class MyStudentManager {
//登陆入口
public static void main(String[] args) {
ArrayList<Student> aList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
System.out.println("----欢迎使用上午茶的学生管理系统-------");
System.out.println("----1.请选择注册----2.请选择登陆----");
int a = scanner.nextInt();
boolean flag = false;
switch (a) {
case 1:
registrStudent(aList);
flag = loginStudent(aList);
if (flag) {
inter(aList);
}
break;
case 2:
flag = loginStudent(aList);
if (flag) {
inter(aList);
}
break;
default:
System.out.println("谢谢你的使用");
System.exit(0);
break;
}
}
//功能界面
public static void inter(ArrayList<Student> aList) {
Scanner scanner = new Scanner(System.in);
while(true) {
System.out.println("----欢迎来到上午茶的学生管理系统界面功能-");
System.out.println("----1.查看所有学生信息-------------");
System.out.println("----2.添加学生------------------");
System.out.println("----3.删除学生------------------");
System.out.println("----4.修改学生------------------");
System.out.println("----5.找出所有女同学--------------");
System.out.println("----6.重登陆系统------------------");
System.out.println("----7.修改密码------------------");
System.out.println("----8.退出系统------------------");
System.out.println("请输入你选择:");
String choiString = scanner.nextLine();
//使用switch语句选择功能
switch (choiString) {
case "1":
//查看所有学生
findAllStudent(aList);
break;
case "2":
//添加学生
addStudent(aList);
break;
case "3":
//删除学生
deletStudent(aList);
break;
case "4":
updateStudent(aList);
//修改学生
break;
case "5":
//找出所有女同学
checkStudent(aList);
break;
case "6":
//重登系统
boolean flag = loginStudent(aList);
if (flag) {
inter(aList);
}
break;
case "7":
//修改用户密码
updatePassword(aList);
break;
default:
System.out.println("谢谢你的使用");
System.exit(0);
break;
}
}
}
//查看学生
public static void findAllStudent(ArrayList<Student> aList) {
if (aList.size()==0) {
System.out.println("不好意思,没有任何学生信息可查,请返回重新选择。");
return;
}
System.out.println("学号\t\t姓名\t性别\t年龄\t学科\t居住地");
for (int i = aList.size()-1; i >=0; i--){
Student s = aList.get(i);
System.out.println(s.getId( )+"\t"+s.getName()+"\t"+s.getSex()+"\t"+s.getAge()+"\t"+s.getSubject()+"\t"+s.getAdderss());
}
}
//添加学生
public static void addStudent(ArrayList<Student> aList){
Scanner scanner = new Scanner(System.in);
while(true) {
boolean flag = false;
System.out.println("请输入学生学号:");
String id = scanner.nextLine();
for (int i = aList.size()-1; i >= 0; i--) {
Student s1 = aList.get(i);
if (id.equals(aList.get(i).getId())) {
flag = true;
break;
}
}
if (!flag) {
System.out.println("请输入学生姓名:");
String name = scanner.nextLine();
System.out.println("请输入性别:");
String sex= scanner.nextLine();
System.out.println("请输入学生年龄:");
String age = scanner.nextLine();
System.out.println("请输入学生学科:");
String subj = scanner.nextLine();
System.out.println("请输入居住地:");
String address= scanner.next();
Student s1 = new Student(id, name, sex, age, subj, address);
aList.add(s1);
System.out.println("添加成功");
return;
}else {
System.out.println("该学生已经存在,请重新选择");
}
}
}
//删除学生
public static void deletStudent(ArrayList<Student> aList) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要删除的学生的学号:");
String id = scanner.nextLine();
int index = -1;
for (int i = aList.size()-1; i >=0; i--){
Student s1 = aList.get(i);
if (s1.getId().equals(id)) {
index = i;
break;
}
}
if (index==-1) {
System.out.println("不好意思,你要删除的学号的信息不存在,请重新选择。");
}else {
aList.remove(index);
System.out.println("删除学生成功");
}
}
//修改学生
public static void updateStudent(ArrayList<Student>aList) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要修改的学生的学号:");
String id = scanner.nextLine();
int index = -1;
for (int i = aList.size()-1; i >=0; i--) {
Student student = aList.get(i);
if (student.getId().equals(id)){
index = i;
break;
}
}
if (index ==-1) {
System.out.println("不好意思,你要修改的学号的信息不存在,请重新选择。");
}else {
System.out.println("请输入修改的学号:");
String id1 = scanner.nextLine();
System.out.println("请输入学生姓名:");
String name = scanner.nextLine();
System.out.println("请输入性别:");
String sex= scanner.nextLine();
System.out.println("请输入学生年龄:");
String age = scanner.nextLine();
System.out.println("请输入学生学科:");
String subj = scanner.nextLine();
System.out.println("请输入居住地:");
String address= scanner.next();
Student s1 = new Student(id1, name, sex, age, subj, address);
aList.set(index, s1);
System.out.println("修改成功");
}
}
//找出所有女同学
public static void checkStudent(ArrayList<Student> alList) {
System.out.println("学号\t\t姓名\t性别\t年龄\t学科\t居住地");
for (int i = alList.size()-1; i >= 0; i--) {
Student student = alList.get(i);
if (student.getSex().equals("女")) {
System.out.println(student.getId()+"\t"+student.getName()+"\t"+student.getSex()+"\t"+student.getAge()+"\t"+student.getSubject()+"\t"+student.getAdderss());
}
}
}
//注册功能
public static void registrStudent(ArrayList<Student> alList) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的用户名:");
String admin = scanner.nextLine();
System.out.println("请输入你的密码:");
String password = scanner.nextLine();
Student student = new Student(admin,password);
alList.add(student);
}
//登陆功能
public static boolean loginStudent(ArrayList<Student> alList) {
boolean flag = false;
int count = 3;
while(count>=0) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的注册时的用户名:");
String string = scanner.nextLine();
System.out.println("请输入你的注册时的密码:");
String string1 = scanner.nextLine();
for (int i = alList.size()-1; i >=0; i--) {
if (alList.get(i).getUsrename().equals(string)&&alList.get(i).getPaswword().equals(string1)) {
flag =true;
return flag;
}else if (count==0) {
System.out.println("已输错三次,退出系统,请联系管理员");
System.exit(0);
}else {
count--;
System.out.println("账户密码错误,你还剩"+count+"次");
}
}
}
return flag;
}
//修改账户密码
public static void updatePassword(ArrayList<Student> alList) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你要修改密码的用户名");
String aString = scanner.nextLine();
int index = -1;
for (int i = alList.size()-1; i >= 0; i--) {
Student aString2 = alList.get(i);
if (aString.equals(aString2.getUsrename())) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("不好意思,没有该用户名,请重新选择");
}else {
System.out.println("请输入用户名:");
String str = scanner.nextLine();
System.out.println("请输入密码:");
String str1 = scanner.nextLine();
Student student = new Student(str, str1);
alList.set(index, student);
System.out.println("恭喜你,修改成功");
}
}
}
还有一个学生类 就不发了 加起来 刚好300行代码啦~~~
|
|