Java實現(xiàn)學生管理系統(tǒng)
更新時間:2018年01月12日 10:58:40 作者:北京德潤于大海
這篇文章主要為大家詳細介紹了Java實現(xiàn)學生管理系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下
項目描述:通過管理員帳號登錄,對學員信息進行管理??梢詫崿F(xiàn)學員信息的增加、修改、刪除、查詢。
知識點:數(shù)組、do{}while循環(huán)、for循環(huán)、if語句、switch條件語句
學生管理系統(tǒng)的流程圖
import java.util.Scanner; public class Stu{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); boolean flag = false; int stuNum = 0; String[] stuName = new String[20]; String[] stuId = new String[20]; System.out.println("**********************************"); System.out.println("* *"); System.out.println("* *"); System.out.println("* 歡迎使用德潤科技教務管理系統(tǒng) *"); System.out.println("* *"); System.out.println("* *"); System.out.println("**********************************"); System.out.println("\n"); do{ System.out.println("************************"); System.out.println("請輸入想要執(zhí)行的操作"); System.out.println("1.登錄系統(tǒng) 2.退出系統(tǒng)"); String num1 = sc.next(); if(num1.equals("1")){ flag = false; break; }if(num1.equals("2")){ System.exit(0); flag = false; }else{ System.out.println("輸入有誤請重新輸入"); flag = true; } }while(flag); do{ System.out.println("請輸入登陸賬號"); String username = sc.next(); System.out.println("請輸入密碼"); String password = sc.next(); if(username.equals("tiantian")&&password.equals("dahai")){ System.out.println("歡迎"+username); flag = false; }else{ System.out.println("賬號或者密碼錯誤,請重新登錄"); flag = true; } }while(flag); do{ System.out.println("********************"); System.out.println("請輸入想要進行的操作"); System.out.println("****************************************************************************"); System.out.println("1.增加學員信息 2.刪除學員信息 3.修改學員姓名 4.查看學員信息 5.退出系統(tǒng)"); System.out.println("****************************************************************************"); String num2 = sc.next(); switch(num2){ case "1": System.out.println("請輸入要添加的學員姓名"); stuName[stuNum] = sc.next(); System.out.println("請輸入要添加的學員學號"); stuId[stuNum] = sc.next(); stuNum++; System.out.println("添加成功"); flag = true; break; case "2": System.out.println("請輸入想要刪除的學員的學號"); String stuIdDel = sc.next(); for(int i=0;i<stuName.length;i++){ if(stuIdDel.equals(stuId[i])){ stuId[i] = null; stuName[i] = null; }else{ System.out.println("沒有此學員的學號"); } } flag = true; break; case "3": System.out.println("請輸入想要修改的學員的學號"); String stuIdUp = sc.next(); System.out.println("請輸入新的學員姓名"); String stuNameUp = sc.next(); for(int i=0;i<stuId.length;i++){ if(stuIdUp.equals(stuId[i])){ stuName[i] = stuNameUp; }else{ System.out.println("沒有此學員的學號"); } } flag = true; break; case "4": for(int i=0;i<stuName.length;i++){ if(stuName[i]==null){ continue; } System.out.println("學員的姓名為"+stuName[i]+"\t學員的學號為"+stuId[i]); } flag = true; break; case "5": System.exit(0); default: System.out.println("輸入有誤請重新輸入!!!"); flag = true; } }while(flag); } }
以下為優(yōu)化后的代碼
import java.util.Scanner; public class Stu{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); boolean flag = false; boolean ss = true; boolean aa = true; boolean bb = true; boolean cc = true; int stuNum = 0; String[] stuName = new String[20]; String[] stuId = new String[20]; String[] userNames = new String[5]; String[] passWords = new String[5]; System.out.println("*******************************************************"); System.out.println("* *"); System.out.println("* *"); System.out.println("* 歡迎使用德潤科技教務管理系統(tǒng) *"); System.out.println("* *"); System.out.println("* *"); System.out.println("*******************************************************"); System.out.println("\n"); do{ System.out.println("************************"); if(userNames[0]==null){ System.out.println("請輸入想要執(zhí)行的操作(你還沒有登陸賬號請先注冊)"); }else{ System.out.println("請輸入想要執(zhí)行的操作(您已注冊管理員身份,可以登錄系統(tǒng))"); } System.out.println("1.注冊帳號 2.登錄系統(tǒng) 3.忘記密碼 4.退出系統(tǒng)"); String num1 = sc.next(); switch(num1){ case "1": do{ System.out.println("請輸入想要注冊的用戶名"); userNames[stuNum] = sc.next(); System.out.println("請輸入想要注冊的密碼"); String password1 = sc.next(); System.out.println("請再次輸入密碼"); String password2 = sc.next(); if(password1.equals(password2)){ passWords[stuNum] = password1; System.out.println("恭喜!帳號:"+userNames[stuNum]+"創(chuàng)建成功"); flag = true; }else{ System.out.println("兩次輸入的密碼不一致請重新創(chuàng)建"); flag = false; } }while(!flag); stuNum++; continue; case "2": flag = false; break; case "3": System.out.println("請輸入要查詢密碼的帳號"); String username1 = sc.next(); for(int i=0;i<userNames.length;i++){ if(username1.equals(userNames[i])){ System.out.println("帳號"+username1+"的密碼為"+passWords[i]); aa = false; } flag = true; } if(aa == true){ System.out.println("無此帳號信息"); aa = true; flag = true; } continue; case "4": System.exit(0); flag = false; default: System.out.println("輸入有誤請重新輸入"); flag = true; } }while(flag); do{ System.out.println("請輸入登陸賬號"); String username = sc.next(); System.out.println("請輸入密碼"); String password = sc.next(); for(int i=0;i<userNames.length;i++){ if(username.equals(userNames[i])&&password.equals(passWords[i])){ System.out.println("歡迎"+username); ss = false; break; } } if(ss==true){ System.out.println("賬號或者密碼錯誤,請重新登錄"); ss = true; } }while(ss); do{ System.out.println("********************"); System.out.println("請輸入想要進行的操作"); System.out.println("****************************************************************************"); System.out.println("1.增加學員信息 2.刪除學員信息 3.修改學員姓名 4.查看學員信息 5.退出系統(tǒng)"); System.out.println("****************************************************************************"); String num2 = sc.next(); switch(num2){ case "1": System.out.println("請輸入要添加的學員姓名"); stuName[stuNum] = sc.next(); System.out.println("請輸入要添加的學員學號"); stuId[stuNum] = sc.next(); stuNum++; System.out.println("添加成功"); flag = true; break; case "2": System.out.println("請輸入想要刪除的學員的學號"); String stuIdDel = sc.next(); for(int i=0;i<stuName.length;i++){ if(stuIdDel.equals(stuId[i])){ stuId[i] = stuId[stuId.length-1]; stuName[i] = stuName[stuName.length-1]; System.out.println("刪除成功!"); flag = true; cc = false; } }if(cc == true){ System.out.println("沒有此學員的學號"); flag = true; } break; case "3": System.out.println("請輸入想要修改的學員的學號"); String stuIdUp = sc.next(); for(int i=0;i<stuId.length;i++){ if(stuIdUp.equals(stuId[i])){ System.out.println("請輸入新的學員姓名"); String stuNameUp = sc.next(); stuName[i] = stuNameUp; System.out.println("修改成功!"); flag = true; bb = false; } } if(bb==true){ System.out.println("沒有此學員的學號"); flag = true; }break; case "4": for(int i=0;i<stuName.length;i++){ if(stuName[i]==null){ continue; } System.out.println("學員的姓名為"+stuName[i]+"\t學員的學號為"+stuId[i]); } flag = true; break; case "5": System.exit(0); default: System.out.println("輸入有誤請重新輸入!!!"); flag = true; } }while(flag); } }
本代碼為Java初級人員編寫,方法運用不是很恰當,僅供娛樂。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
java.sql.SQLRecoverableException關閉的連接異常問題及解決辦法
當數(shù)據(jù)庫連接池中的連接被創(chuàng)建而長時間不使用的情況下,該連接會自動回收并失效,就導致客戶端程序報“ java.sql.SQLException: Io 異常: Connection reset” 或“java.sql.SQLException 關閉的連接”異常問題,下面給大家分享解決方案,一起看看吧2024-03-03Spring集成MyBatis?及Aop分頁的實現(xiàn)代碼
這篇文章主要介紹了Spring集成MyBatis?及Aop分頁的實現(xiàn),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04