1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
| import java.util.ArrayList; import java.util.Scanner;
public class Main { static int choiceAdmin; static Scanner sc = new Scanner(System.in); static ArrayList<User> arrayListUser = new ArrayList<>(); static ArrayList<Student> arrayListStudent = new ArrayList<>();
public static void main(String[] args) { while (true) { interfaceMain(); } }
public static void interfaceMain() { System.out.println("-------------欢迎来到学生管理系统----------------"); System.out.println("请选择你的身份"); System.out.println("1.学生"); System.out.println("2.管理员"); System.out.println("请输入你的选择:"); choiceAdmin = sc.nextInt(); if (choiceAdmin == 1) { interfaceUser(); } else if (choiceAdmin == 2) { interfaceUser(); } else { System.out.println("输入错误,请重新输入"); } }
public static void interfaceStudent() { System.out.println("----------------------------------------------"); System.out.println("请选择你的操作"); System.out.println("1.查看个人信息"); System.out.println("2.修改个人信息"); System.out.println("3.退出"); System.out.println("请输入你的选择:"); }
public static void interfaceAdmin() { System.out.println("----------------------------------------------"); 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("请输入你的选择:"); }
public static void interfaceUser() { System.out.println("----------------------------------------------"); System.out.println("请选择你的操作"); System.out.println("1.登录"); System.out.println("2.注册"); System.out.println("3.忘记密码"); System.out.println("4.退出"); System.out.println("请输入你的选择:"); int choice = sc.nextInt(); switch (choice) { case 2: register(); break; } }
public static boolean register() { User user = new User(); if (choiceAdmin == 1) { user.setCharacter(1); } else if (choiceAdmin == 2) { user.setCharacter(2); } else { System.out.println("输入错误,请重新输入"); } String name; while (true) { System.out.println("请输入你的用户名:"); name = sc.next(); if (checkUserName(arrayListUser, name)) { break; } else { System.out.println("用户名不符合规范,请重新输入"); } } user.setName(name); String password1, password2; while (true) { System.out.println("请输入你的密码:"); password1 = sc.nextLine(); System.out.println("请再次输入你的密码:"); password2 = sc.nextLine(); if (password2.equals(password1)) { user.setPassword(password1); break; } System.out.println("两次密码不一致,请重新输入"); } String identity_id; while (true) { System.out.println("请输入你的身份证号:"); identity_id = sc.nextLine(); if (checkIdentityId(identity_id)) { break; } else { System.out.println("身份证号不符合规范,请重新输入"); } } user.setIdentity_id(identity_id); String phone; while (true) { System.out.println("请输入你的手机号:"); phone = sc.nextLine(); if (checkPhone(phone)) { break; } System.out.println("手机号不符合规范,请重新输入"); } return true; }
public static boolean checkUserName(ArrayList<User> ListUser, String name) { if (name.length() < 3 || name.length() > 15) { return false; } for (int i = 0; i < ListUser.size(); i++) { if (ListUser.get(i).getName().equals(name)) { return false; } } for (int i = 0; i < name.length(); i++) { if (name.charAt(i) < '0' || name.charAt(i) > '9') { return false; } } return true; }
public static boolean checkIdentityId(String identity_id) { if (identity_id.length() != 18) { return false; } if (identity_id.charAt(0) == 0) { return false; } for (int i = 0; i < 17; i++) { if (identity_id.charAt(i) < '0' || identity_id.charAt(i) > '9') { return false; } } if (identity_id.charAt(17) < '0' || identity_id.charAt(17) > '9' || identity_id.charAt(17) != 'X' || identity_id.charAt(17) != 'x') { return false; } return true; }
public static boolean checkPhone(String phone) { if (phone.length() != 11) { return false; } if (phone.charAt(0) != '1') { return false; } for (int i = 0; i < 11; i++) { if (phone.charAt(i) < '0' || phone.charAt(i) > '9') { return false; } } return true; } }
|