Java-学生管理系统 需求文档:
代码展示 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 package Management_System;public class Stu { private int id; private String name; private int age; private String home; public Stu () { } public Stu (int id, String name, int age, String home) { this .id = id; this .name = name; this .age = age; this .home = home; } public int getId () { return id; } public void setId (int id) { this .id = id; } public String getName () { return name; } public void setName (String name) { this .name = name; } public int getAge () { return age; } public void setAge (int age) { this .age = age; } public String getHome () { return home; } public void setHome (String home) { this .home = home; } }
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 package Management_System;import java.util.ArrayList;import java.util.Arrays;import java.util.Scanner;public class stu_System { public static void MeNu () { 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("请输入你的选择:" ); } public static void AddStu (ArrayList<Stu>Stu1) { System.out.println("开始添加学生,请输入学生ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stu1,ID)&&ID>=0 ){ Stu Stupeople=new Stu (); Stupeople.setId(ID); System.out.println("请输入学生姓名" ); String name=s.next(); Stupeople.setName(name); System.out.println("请输入学生年龄" ); int age=s.nextInt(); Stupeople.setAge(age); System.out.println("请输入学生家庭住址" ); String home=s.next(); Stupeople.setHome(home); Stu1.add(Stupeople); System.out.println("信息录入完毕!!!!" ); }else { System.out.println("输入错误:你输入的ID已经记录过" ); } } public static boolean checkId (ArrayList<Stu>Stu1,int ID) { for (int i = 0 ; i < Stu1.size(); i++) { if (Stu1.get(i).getId()==ID)return false ; } return true ; } public static void Delete_stu (ArrayList<Stu>Stuj) { System.out.println("请输入你要删除学生的ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stuj,ID)){ System.out.println("删除失败,你要删除的学生不存在!!" ); }else { for (int i = 0 ; i < Stuj.size(); i++) { if (Stuj.get(i).getId()==ID)Stuj.remove(i); } System.out.println("学生删除成功!!!" ); } } public static void ChangeStu (ArrayList<Stu>Stuj) { System.out.println("请输入你要修改学生的ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stuj,ID)){ System.out.println("ID输入错误,此ID学生不存在" ); }else { for (int i = 0 ; i < Stuj.size(); i++) { if (Stuj.get(i).getId()==ID){ System.out.println("请输入修改后的学生姓名" ); String name=s.next(); Stuj.get(i).setName(name); System.out.println("请输入修改后的学生年龄" ); int age=s.nextInt(); Stuj.get(i).setAge(age); System.out.println("请输入修改后的学生家庭住址" ); String home=s.next(); Stuj.get(i).setHome(home); System.out.println("信息更新成功!!" ); } } } } public static void SpellStu (ArrayList<Stu>Stuj) { System.out.println("id\t姓名\t年龄\t家庭住址" ); for (int i = 0 ; i < Stuj.size(); i++) { System.out.print(Stuj.get(i).getId()+"\t" ); System.out.print(Stuj.get(i).getName()+"\t" ); System.out.print(Stuj.get(i).getAge()+"\t" ); System.out.println(Stuj.get(i).getHome()+"\t" ); } } public static void main (String[] args) { ArrayList<Stu> Stuj=new ArrayList <>(); int x=1 ; while (x==1 ){ MeNu(); Scanner s=new Scanner (System.in); byte choose=s.nextByte(); if (choose<1 ||choose>5 ) System.out.println("笨蛋!看着点菜单啊喂~~" ); switch (choose){ case 1 : AddStu(Stuj); break ; case 2 : Delete_stu(Stuj); break ; case 3 : ChangeStu(Stuj); break ; case 4 : SpellStu(Stuj); break ; case 5 : x=0 ; break ; } } } }
代码到这里就完了,后面会更新升级版的题目,慢慢加难度
Java-学生管理系统升级版 需求文档:
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 package login;public class user { private String username; private String userpassword; private String userID; private String userphonenumber; public user () { } public user (String username, String userpassword, String userID, String userphonenumber) { this .username = username; this .userpassword = userpassword; this .userID = userID; this .userphonenumber = userphonenumber; } public String getUsername () { return username; } public void setUsername (String username) { this .username = username; } public String getUserpassword () { return userpassword; } public void setUserpassword (String userpassword) { this .userpassword = userpassword; } public String getUserID () { return userID; } public void setUserID (String userID) { this .userID = userID; } public String getUserphonenumber () { return userphonenumber; } public void setUserphonenumber (String userphonenumber) { this .userphonenumber = userphonenumber; } }
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 package login;import java.util.ArrayList;import java.util.Arrays;import java.util.Random;import java.util.Scanner;import java.util.concurrent.TimeUnit;public class window { public static void register (ArrayList<user>s) { user user1=new user (); System.out.println("创建你的用户名" ); Scanner sc=new Scanner (System.in); String username=sc.next(); if (UnSameName(s,username)){ if (username.length()>=3 &&username.length()<=15 ){ byte count=0 ; for (int i = 0 ; i < username.length(); i++) { if (username.charAt(i)+0 >=48 &&username.charAt(i)+0 <=57 )count++; } if (count==username.length()||count==0 ){ System.out.println("输入的姓名必须是数字和字母的混合" ); }else { user1.setUsername(username); System.out.println("请设置你的密码" ); String password=sc.next(); System.out.println("请再次输入你的密码" ); String password1= sc.next(); if (password.equals(password1)){ user1.setUserpassword(password1); System.out.println("请输入你的身份证号码" ); String idcard=sc.next(); if (idcard.charAt(0 )!=0 &&idcard.length()==18 &&check(idcard)&&check2(idcard.charAt(idcard.length()-1 ))){ user1.setUserID(idcard); System.out.println("请输入你的手机号码" ); String phone=sc.next(); if (num(phone)&&phone.charAt(0 )!=0 &&phone.length()==11 ){ user1.setUserphonenumber(phone); s.add(user1); }else { System.out.println("手机号输入错误" ); } }else { System.out.println("身份证号输入错误!" ); } }else { System.out.println("两次密码输入不一致,请重新输入!!" ); } } }else { System.out.println("创建的用户名长度必须在3~15之间" ); } }else { System.out.println("姓名重复" ); } } public static boolean UnSameName (ArrayList<user>s,String name) { for (int i = 0 ; i < s.size(); i++) { if (s.get(i).getUsername()==name)return false ; } return true ; } public static boolean check (String idcard) { for (int i = 0 ; i < idcard.length()-1 ; i++) { if (idcard.charAt(i)+0 <48 ||idcard.charAt(i)+0 >57 )return false ; } return true ; } public static boolean check2 (Character a) { if ((a+0 >=48 &&a+0 <=57 )||(a.equals('x' ))||(a.equals('X' )))return true ; return false ; } public static boolean num (String phone) { for (int i = 0 ; i < phone.length(); i++) { if (phone.charAt(i)+0 <48 ||phone.charAt(i)+0 >57 )return false ; } return true ; } public static void Login (ArrayList<user>s) { System.out.println("请输入用户名" ); Scanner sc=new Scanner (System.in); String username= sc.next(); int where=userNum(s,username); if (where==(-1 )){ System.out.println("用户未注册,请先注册" ); }else { System.out.println("请输入密码" ); String password=sc.next(); String YZM=YZM(); System.out.println("验证码:" +YZM); System.out.println("请输入验证码" ); String YZMuser=sc.next(); if (YZMuser.equalsIgnoreCase(YZM)){ if (s.get(where).getUserpassword().equals(password)){ System.out.println("登录成功!即将进入学生管理系统" ); YC(); System.out.println("欢迎管理员" ); }else { System.out.println("密码或用户名错误请检查后继续!" ); } }else { System.out.println("验证码输入错误" ); } } } public static int userNum (ArrayList<user>s,String username) { for (int i = 0 ; i < s.size(); i++) { if (s.get(i).getUsername().equals(username)) { return i; } } return -1 ; } public static String YZM () { char []arr=new char [5 ]; Random s=new Random (); for (int i = 0 ; i < arr.length-1 ; i++) { int num3=s.nextInt(2 ); switch (num3){ case 0 : arr[i]=(char )(s.nextInt(26 )+97 ); break ; case 1 : arr[i]=(char )(s.nextInt(26 )+65 ); break ; } } arr[arr.length-1 ]=(char )(s.nextInt(10 )+48 ); int num4=s.nextInt(5 ); char a=arr[num4]; arr[num4]=arr[arr.length-1 ]; arr[arr.length-1 ]=a; String resul=new String (arr); return resul; } public static String YZM2 () { String str="" ; Random Sj=new Random (); int count=0 ; do { while (str.length()!=5 ){ int choose=Sj.nextInt(3 ); switch (choose){ case 0 : str=str+(char )(Sj.nextInt(26 )+65 ); break ; case 1 : str=str+(char )(Sj.nextInt(26 )+97 ); break ; case 2 : if (count==1 )break ; str=str+Sj.nextInt(10 ); count++; break ; } } }while (count==0 ); System.out.println(str); return str; } public static void YC () { try { Thread.sleep(5000 ); } catch (InterruptedException e) { e.printStackTrace(); } } public static void Forgotpassword (ArrayList<user>s) { System.out.println("请输入你的用户名" ); Scanner sc=new Scanner (System.in); String Uname= sc.next(); if (userNum(s,Uname)==(-1 )){ System.out.println("用户不存在,请先注册!" ); }else { System.out.println("输入你留的身份证号进行验证" ); String IDcard=sc.next(); System.out.println("输入你留的手机号进行验证" ); String Phone= sc.next(); int numWhere=userNum(s,Uname); if (s.get(numWhere).getUserID().equals(IDcard)&&s.get(numWhere).getUserphonenumber().equals(Phone)){ System.out.println("验证成功!请输入新创建的密码" ); String password=sc.next(); System.out.println("请再次输入你的密码" ); String password1= sc.next(); if (password.equals(password1)){ s.get(numWhere).setUserpassword(password); System.out.println("密码更改成功" ); }else { System.out.println("两次密码输入不一致" ); } }else { System.out.println("输入的身份证或手机号错误,请检查后继续" ); } } } public static void test (ArrayList<user>s) { user First1=new user ("默认用户0" ,"0" ,"111111111111111111" ,"11111111111" ); s.add(First1); } public static void main (String[] args) { ArrayList<user> s=new ArrayList <>(); while (true ){ System.out.println("欢迎来到学生管理系统" ); System.out.println("请选择操作:1.登录 2.注册 3.忘记密码" ); Scanner sc=new Scanner (System.in); byte choose=sc.nextByte(); switch (choose){ case 1 : Login(s); break ; case 2 : register(s); break ; case 3 : Forgotpassword(s); break ; default : System.out.println("你的输入有误请重新输入!!!" ); } } } }
最终作品 需求 当你看到这里应该是上面的两个系统都写完了,那现在就是把他们结合起来了,
得先进行管理员用户登录才能进行学生管理 代码展示 创建用户类
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 package login;public class user { private String username; private String userpassword; private String userID; private String userphonenumber; public user () { } public user (String username, String userpassword, String userID, String userphonenumber) { this .username = username; this .userpassword = userpassword; this .userID = userID; this .userphonenumber = userphonenumber; } public String getUsername () { return username; } public void setUsername (String username) { this .username = username; } public String getUserpassword () { return userpassword; } public void setUserpassword (String userpassword) { this .userpassword = userpassword; } public String getUserID () { return userID; } public void setUserID (String userID) { this .userID = userID; } public String getUserphonenumber () { return userphonenumber; } public void setUserphonenumber (String userphonenumber) { this .userphonenumber = userphonenumber; } }
创建学生类
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 package login;public class Stu { private int id; private String name; private int age; private String home; public Stu () { } public Stu (int id, String name, int age, String home) { this .id = id; this .name = name; this .age = age; this .home = home; } public int getId () { return id; } public void setId (int id) { this .id = id; } public String getName () { return name; } public void setName (String name) { this .name = name; } public int getAge () { return age; } public void setAge (int age) { this .age = age; } public String getHome () { return home; } public void setHome (String home) { this .home = home; } }
编写主方法
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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 package login;import java.util.ArrayList;import java.util.Random;import java.util.Scanner;public class window { public static void register (ArrayList<user>s) { user user1=new user (); System.out.println("创建你的用户名" ); Scanner sc=new Scanner (System.in); String username=sc.next(); if (UnSameName(s,username)){ if (username.length()>=3 &&username.length()<=15 ){ byte count=0 ; for (int i = 0 ; i < username.length(); i++) { if (username.charAt(i)+0 >=48 &&username.charAt(i)+0 <=57 )count++; } if (count==username.length()||count==0 ){ System.out.println("输入的姓名必须是数字和字母的混合" ); }else { user1.setUsername(username); System.out.println("请设置你的密码" ); String password=sc.next(); System.out.println("请再次输入你的密码" ); String password1= sc.next(); if (password.equals(password1)){ user1.setUserpassword(password1); System.out.println("请输入你的身份证号码" ); String idcard=sc.next(); if (idcard.charAt(0 )!=0 &&idcard.length()==18 &&check(idcard)&&check2(idcard.charAt(idcard.length()-1 ))){ user1.setUserID(idcard); System.out.println("请输入你的手机号码" ); String phone=sc.next(); if (num(phone)&&phone.charAt(0 )!=0 &&phone.length()==11 ){ user1.setUserphonenumber(phone); s.add(user1); }else { System.out.println("手机号输入错误" ); } }else { System.out.println("身份证号输入错误!" ); } }else { System.out.println("两次密码输入不一致,请重新输入!!" ); } } }else { System.out.println("创建的用户名长度必须在3~15之间" ); } }else { System.out.println("姓名重复" ); } } public static boolean UnSameName (ArrayList<user>s,String name) { for (int i = 0 ; i < s.size(); i++) { if (s.get(i).getUsername()==name)return false ; } return true ; } public static boolean check (String idcard) { for (int i = 0 ; i < idcard.length()-1 ; i++) { if (idcard.charAt(i)+0 <48 ||idcard.charAt(i)+0 >57 )return false ; } return true ; } public static boolean check2 (Character a) { if ((a+0 >=48 &&a+0 <=57 )||(a.equals('x' ))||(a.equals('X' )))return true ; return false ; } public static boolean num (String phone) { for (int i = 0 ; i < phone.length(); i++) { if (phone.charAt(i)+0 <48 ||phone.charAt(i)+0 >57 )return false ; } return true ; } public static void Login (ArrayList<user>s) { System.out.println("请输入用户名" ); Scanner sc=new Scanner (System.in); String username= sc.next(); int where=userNum(s,username); if (where==(-1 )){ System.out.println("用户未注册,请先注册" ); }else { System.out.println("请输入密码" ); String password=sc.next(); String YZM=YZM(); System.out.println("验证码:" +YZM); System.out.println("请输入验证码" ); String YZMuser=sc.next(); if (YZMuser.equalsIgnoreCase(YZM)){ if (s.get(where).getUserpassword().equals(password)){ System.out.println("登录成功!即将进入学生管理系统" ); YC(); System.out.println("欢迎管理员" +s.get(where).getUsername()); ArrayList<Stu> Stuj=new ArrayList <>(); int x=1 ; while (x==1 ){ MeNu(); Scanner si=new Scanner (System.in); byte choose=si.nextByte(); if (choose<1 ||choose>5 ) System.out.println("笨蛋!看着点菜单啊喂~~" ); switch (choose){ case 1 : AddStu(Stuj); break ; case 2 : Delete_stu(Stuj); break ; case 3 : ChangeStu(Stuj); break ; case 4 : SpellStu(Stuj); break ; case 5 : x=0 ; break ; } } }else { System.out.println("密码或用户名错误请检查后继续!" ); } }else { System.out.println("验证码输入错误" ); } } } public static int userNum (ArrayList<user>s,String username) { for (int i = 0 ; i < s.size(); i++) { if (s.get(i).getUsername().equals(username)) { return i; } } return -1 ; } public static String YZM () { char []arr=new char [5 ]; Random s=new Random (); for (int i = 0 ; i < arr.length-1 ; i++) { int num3=s.nextInt(2 ); switch (num3){ case 0 : arr[i]=(char )(s.nextInt(26 )+97 ); break ; case 1 : arr[i]=(char )(s.nextInt(26 )+65 ); break ; } } arr[arr.length-1 ]=(char )(s.nextInt(10 )+48 ); int num4=s.nextInt(5 ); char a=arr[num4]; arr[num4]=arr[arr.length-1 ]; arr[arr.length-1 ]=a; String resul=new String (arr); return resul; } public static String YZM2 () { String str="" ; Random Sj=new Random (); int count=0 ; do { while (str.length()!=5 ){ int choose=Sj.nextInt(3 ); switch (choose){ case 0 : str=str+(char )(Sj.nextInt(26 )+65 ); break ; case 1 : str=str+(char )(Sj.nextInt(26 )+97 ); break ; case 2 : if (count==1 )break ; str=str+Sj.nextInt(10 ); count++; break ; } } }while (count==0 ); System.out.println(str); return str; } public static void YC () { try { Thread.sleep(5000 ); } catch (InterruptedException e) { e.printStackTrace(); } } public static void Forgotpassword (ArrayList<user>s) { System.out.println("请输入你的用户名" ); Scanner sc=new Scanner (System.in); String Uname= sc.next(); if (userNum(s,Uname)==(-1 )){ System.out.println("用户不存在,请先注册!" ); }else { System.out.println("输入你留的身份证号进行验证" ); String IDcard=sc.next(); System.out.println("输入你留的手机号进行验证" ); String Phone= sc.next(); int numWhere=userNum(s,Uname); if (s.get(numWhere).getUserID().equals(IDcard)&&s.get(numWhere).getUserphonenumber().equals(Phone)){ System.out.println("验证成功!请输入新创建的密码" ); String password=sc.next(); System.out.println("请再次输入你的密码" ); String password1= sc.next(); if (password.equals(password1)){ s.get(numWhere).setUserpassword(password); System.out.println("密码更改成功" ); }else { System.out.println("两次密码输入不一致" ); } }else { System.out.println("输入的身份证或手机号错误,请检查后继续" ); } } } public static void test (ArrayList<user>s) { user First1=new user ("默认用户0" ,"0" ,"111111111111111111" ,"11111111111" ); s.add(First1); } public static void MeNu () { 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("请输入你的选择:" ); } public static void AddStu (ArrayList<Stu>Stu1) { System.out.println("开始添加学生,请输入学生ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stu1,ID)&&ID>=0 ){ Stu Stupeople=new Stu (); Stupeople.setId(ID); System.out.println("请输入学生姓名" ); String name=s.next(); Stupeople.setName(name); System.out.println("请输入学生年龄" ); int age=s.nextInt(); Stupeople.setAge(age); System.out.println("请输入学生家庭住址" ); String home=s.next(); Stupeople.setHome(home); Stu1.add(Stupeople); System.out.println("信息录入完毕!!!!" ); }else { System.out.println("输入错误:你输入的ID已经记录过" ); } } public static boolean checkId (ArrayList<Stu>Stu1,int ID) { for (int i = 0 ; i < Stu1.size(); i++) { if (Stu1.get(i).getId()==ID)return false ; } return true ; } public static void Delete_stu (ArrayList<Stu>Stuj) { System.out.println("请输入你要删除学生的ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stuj,ID)){ System.out.println("删除失败,你要删除的学生不存在!!" ); }else { for (int i = 0 ; i < Stuj.size(); i++) { if (Stuj.get(i).getId()==ID)Stuj.remove(i); } System.out.println("学生删除成功!!!" ); } } public static void ChangeStu (ArrayList<Stu>Stuj) { System.out.println("请输入你要修改学生的ID" ); Scanner s=new Scanner (System.in); int ID=s.nextInt(); if (checkId(Stuj,ID)){ System.out.println("ID输入错误,此ID学生不存在" ); }else { for (int i = 0 ; i < Stuj.size(); i++) { if (Stuj.get(i).getId()==ID){ System.out.println("请输入修改后的学生姓名" ); String name=s.next(); Stuj.get(i).setName(name); System.out.println("请输入修改后的学生年龄" ); int age=s.nextInt(); Stuj.get(i).setAge(age); System.out.println("请输入修改后的学生家庭住址" ); String home=s.next(); Stuj.get(i).setHome(home); System.out.println("信息更新成功!!" ); } } } } public static void SpellStu (ArrayList<Stu>Stuj) { System.out.println("id\t姓名\t\t年龄\t家庭住址" ); for (int i = 0 ; i < Stuj.size(); i++) { System.out.print(Stuj.get(i).getId()+"\t" ); System.out.print(Stuj.get(i).getName()+"\t" ); if (Stuj.get(i).getName().length()<3 ) System.out.print("\t" ); System.out.print(Stuj.get(i).getAge()+"\t" ); System.out.println(Stuj.get(i).getHome()+"\t" ); } } public static void main (String[] args) { ArrayList<user> s=new ArrayList <>(); test(s); while (true ){ System.out.println("欢迎来到学生管理系统" ); System.out.println("请选择操作:1.登录 2.注册 3.忘记密码" ); Scanner sc=new Scanner (System.in); byte choose=sc.nextByte(); switch (choose){ case 1 : Login(s); break ; case 2 : register(s); break ; case 3 : Forgotpassword(s); break ; default : System.out.println("你的输入有误请重新输入!!!" ); } } } }