Java實(shí)現(xiàn)班級管理系統(tǒng)
本文為大家分享了Java實(shí)現(xiàn)班級管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
需求:班級管理系統(tǒng)
功能:對學(xué)生的信息進(jìn)行管理
1 登錄系統(tǒng) 2 退出系統(tǒng)
賬號:
密碼:
驗(yàn)證碼
-----歡迎來到班級管理系統(tǒng)-----
1 添加學(xué)生信息:
2 刪除學(xué)生信息
3 查找指定學(xué)生信息:
4 查找所有學(xué)生信息
5 統(tǒng)計(jì)班級信息
6 退出
請選擇您要查詢的序號:
建立一個(gè)Student類:
public class Student { ? ? private String sid; // 學(xué)號 ? ? private String name; // 姓名 ? ? private int age; // 年齡 ? ? private String sex; // 性別 ? ? private String brithday; // 生日 ? ? private String constellation; // 星座 ? ? private String message; // 查看班級信息 ? ? public Student(){ ? ? } ? ? public Student(String sid, String name, int age, String sex, String brithday, String constellation, String message) { ? ? ? ? this.sid = sid; ? ? ? ? this.name = name; ? ? ? ? this.age = age; ? ? ? ? this.sex = sex; ? ? ? ? this.brithday = brithday; ? ? ? ? this.constellation = constellation; ? ? ? ? this.message = message; ? ? } ? ? public String getSid() { ? ? ? ? return sid; ? ? } ? ? public void setSid(String sid) { ? ? ? ? this.sid = sid; ? ? } ? ? 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 getSex() { ? ? ? ? return sex; ? ? } ? ? public void setSex(String sex) { ? ? ? ? this.sex = sex; ? ? } ? ? public String getBrithday() { ? ? ? ? return brithday; ? ? } ? ? public void setBrithday(String brithday) { ? ? ? ? this.brithday = brithday; ? ? } ? ? public String getConstellation() { ? ? ? ? return constellation; ? ? } ? ? public void setConstellation(String constellation) { ? ? ? ? this.constellation = constellation; ? ? } ? ? public String getMessage(){ ? ? ? ? return message; ? ? } ? ? public void setMessage(String message){ ? ? ? ? this.message = message; ? ? } }
在建立一個(gè)測試類StudentDemo:
1.先實(shí)現(xiàn)界面
public static void main(String[] args) { ? ? ? ? ArrayList<Student> list = new ArrayList<>(); ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? Random random = new Random(); ? ? ? ? // 登錄系統(tǒng) ? ? ? ? lo: ? ? ? ? while(true){ ? ? ? ? ? ? System.out.println("1 登錄系統(tǒng)" + " " + "2 退出系統(tǒng)"); ? ? ? ? ? ? String count = sc.next(); ? ? ? ? ? ? switch(count){ ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? //輸入賬號密碼 ? ? ? ? ? ? ? ? ? ? int num = 0; ? ? ? ? ? ? ? ? ? ? for (int i = 0; i < 3; i++) { ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請輸入管理員賬號:"); ? ? ? ? ? ? ? ? ? ? ? ? String uesr = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請輸入管理員密碼:"); ? ? ? ? ? ? ? ? ? ? ? ? String password = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? // 驗(yàn)證碼 ? ? ? ? ? ? ? ? ? ? ? ? ? ? String code = "1234567890zxcvbnmlkjhgfdsaqwertyuiopZMXNCBVLAKSJDHFGQPWOEIRUTY"; ? ? ? ? ? ? ? ? ? ? ? ? ? ? StringBuilder ss= new StringBuilder(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? int number = code.length(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? for (int j = 0; j < 4; j++) { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int a = random.nextInt(number); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? char ch = code.charAt(a); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ss.append(ch); ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? ? ? while (true){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("請輸入驗(yàn)證碼:" + ss); ? ? ? ? ? ? ? ? ? ? ? ? ? ? String Code = sc.next(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.print("驗(yàn)證碼:" + Code); ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(Code.equalsIgnoreCase(ss.toString())){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("驗(yàn)證成功!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的有誤,請重新輸入!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? if(uesr.equals("admin") && password.equals("123456")){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("登錄成功!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? break lo; ? ? ? ? ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? num++; ? ? ? ? ? ? ? ? ? ? ? ? ? ? if(num < 3){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的賬號或密碼錯(cuò)誤,請重新輸入!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? System.out.println("您已連續(xù)三次輸入錯(cuò)誤,請24小時(shí)以后再次嘗試!"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? case "2": ? ? ? ? ? ? ? ? ? ? return; ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的有誤,請重新輸入!"); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? // 登錄界面 ? ? ? ? Scanner s = new Scanner(System.in); ? ? ? ? la: ? ? ? ? while(true){ ? ? ? ? ? ? System.out.println("-----歡迎來到班級管理系統(tǒng)-----"); ? ? ? ? ? ? System.out.println("1 添加學(xué)生信息:"); ? ? ? ? ? ? System.out.println("2 刪除學(xué)生信息"); ? ? ? ? ? ? System.out.println("3 查找指定學(xué)生信息:"); ? ? ? ? ? ? System.out.println("4 查找所有學(xué)生信息"); ? ? ? ? ? ? System.out.println("5 統(tǒng)計(jì)班級信息"); ? ? ? ? ? ? System.out.println("6 退出"); ? ? ? ? ? ? System.out.println("請選擇您要查詢的序號:"); ? ? ? ? ? ? // 選擇要執(zhí)行的代碼塊 ? ? ? ? ? ? String num = sc.next(); ? ? ? ? ? ? switch(num){ ? ? ? ? ? ? ? ? case "1": ? ? ? ? ? ? ? ? ? ? // System.out.println("1 添加學(xué)生信息:"); ? ? ? ? ? ? ? ? ? ? addStudent(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "2": ? ? ? ? ? ? ? ? ? ? // System.out.println("2 刪除學(xué)生信息"); ? ? ? ? ? ? ? ? ? ? deleteStudent(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "3": ? ? ? ? ? ? ? ? ? ? // System.out.println("3 查找指定學(xué)生信息:"); ? ? ? ? ? ? ? ? ? ? locatingStudent(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "4": ? ? ? ? ? ? ? ? ? ? // System.out.println("4 查找所有學(xué)生信息"); ? ? ? ? ? ? ? ? ? ? setStudent(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "5": ? ? ? ? ? ? ? ? ? ? // System.out.println("5 統(tǒng)計(jì)班級信息"); ? ? ? ? ? ? ? ? ? ? printMessage(list); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? ? ? case "6": ? ? ? ? ? ? ? ? ? ? System.out.println("退出"); ? ? ? ? ? ? ? ? ? ? break la; ? ? ? ? ? ? ? ? default: ? ? ? ? ? ? ? ? ? ? System.out.println("您輸入的有誤請重新輸入!"); ? ? ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? } ? ? ? ? } ? ? }
2.建立一個(gè)判斷系統(tǒng)中是否存在學(xué)生的類
// 判斷學(xué)生是否存在 ? ? public static int getIndex(ArrayList<Student> list,String sid){ ? ? ? ? int index = -1; // 無信息 ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? Student stu = list.get(i); ? ? ? ? ? ? String id = stu.getSid(); ? ? ? ? ? ? if(id.equals(sid)){ ? ? ? ? ? ? ? ? index = i; // 學(xué)生的索引位置 ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? return index; ? ? }
3.添加學(xué)生
//添加學(xué)生 ? ? public static void addStudent(ArrayList<Student> list) { ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? String sid; ? ? ? ? while(true){ ? ? ? ? ? ? System.out.println("請輸入學(xué)號"); ? ? ? ? ? ? sid = sc.next(); ? ? ? ? ? ? int index = getIndex(list,sid); ? ? ? ? ? ? if(index == -1){ ? ? ? ? ? ? ? ? break; ? ? ? ? ? ? }else{ ? ? ? ? ? ? ? ? System.out.println("您輸入的學(xué)號已存在,請重新輸入!"); ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? System.out.println("請輸入您的姓名:"); ? ? ? ? String name = sc.next(); ? ? ? ? System.out.println("請輸入您的年齡:"); ? ? ? ? int age = sc.nextInt(); ? ? ? ? System.out.println("請輸入您的性別:"); ? ? ? ? String sex = sc.next(); ? ? ? ? System.out.println("請輸入您的生日:"); ? ? ? ? String brithday = sc.next(); ? ? ? ? System.out.println("請輸入您的小組:"); ? ? ? ? String groud = sc.next(); ? ? ? ? System.out.println("請輸入您的星座:"); ? ? ? ? String constellation = sc.next(); ? ? ? ? Student stu = new Student(sid,name,age,sex,brithday,groud,constellation); ? ? ? ? list.add(stu); ? ? ? ? System.out.println("添加成功!"); ? ? }
4.刪除學(xué)生
// 刪除學(xué)生 ? ? public static void deleteStudent(ArrayList<Student> list) { ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? System.out.println("請輸入您要?jiǎng)h除的學(xué)號:"); ? ? ? ? String sid = sc.next(); ? ? ? ? int index = getIndex(list,sid); ? ? ? ? if(index == -1){ ? ? ? ? ? ? System.out.println("您輸入的學(xué)生號不存在!"); ? ? ? ? ? ? return; ? ? ? ? }else{ ? ? ? ? ? ? list.remove(index); ? ? ? ? ? ? System.out.println("刪除成功!"); ? ? ? ? } ? ? }
5.查找指定學(xué)生信息
// 查找指定學(xué)生 ? ? public static void locatingStudent(ArrayList<Student> list) { ? ? ? ? Scanner sc = new Scanner(System.in); ? ? ? ? System.out.println("請輸入您要查找的學(xué)號:"); ? ? ? ? String sid = sc.next(); ? ? ? ? Student stu = new Student(); ? ? ? ? int index = getIndex(list,sid); ? ? ? ? if(index == -1){ ? ? ? ? ? ? System.out.println("無信息,請?zhí)砑有畔⒅笤诓檎遥?); ? ? ? ? ? ? return; ? ? ? ? }else{ ? ? ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? ? ? Student a = list.get(i); ? ? ? ? ? ? ? ? System.out.println("學(xué)號:" + a.getSid()); ? ? ? ? ? ? ? ? System.out.println("姓名:" + a.getName()); ? ? ? ? ? ? ? ? System.out.println("年齡:" + a.getAge()); ? ? ? ? ? ? ? ? System.out.println("性別:" + a.getSex()); ? ? ? ? ? ? ? ? System.out.println("生日:" + a.getBrithday()); ? ? ? ? ? ? ? ? System.out.println("星座:" + a.getConstellation()); ? ? ? ? ? ? } ? ? ? ? } ? ? }
6.查找所有學(xué)生信息
// 查找所有學(xué)生信息 ? ? public static void setStudent(ArrayList<Student> list) { ? ? ? ? int s = list.size(); ? ? ? ? if(s == 0){ ? ? ? ? ? ? System.out.println("暫無信息,請?zhí)砑右院笤俅尾樵儯?); ? ? ? ? ? ? return; ? ? ? ? } ? ? ? ? System.out.println("學(xué)號\t姓名\t年齡\t性別\t生日\t星座"); ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? Student stu = list.get(i); ? ? ? ? ? ? System.out.println(stu.getSid() + "\t" + stu.getName() + "\t" + stu.getAge() +"\t" + stu.getSex() + "\t" + stu.getBrithday() + "\t" + stu.getConstellation()); ? ? ? ? } ? ? }
7.統(tǒng)計(jì)班級的信息
// 統(tǒng)計(jì)班級信息 ? ? public static void printMessage(ArrayList<Student> list) { ? ? ? ? // 多少人,男女, ? ? ? ? int count = 0; ? ? ? ? int total = list.size(); ? ? ? ? for (int i = 0; i < list.size(); i++) { ? ? ? ? ? ? Student stu = list.get(i); ? ? ? ? ? ? if(stu.getSex().equals("男")){ ? ? ? ? ? ? ? ? count++; ? ? ? ? ? ? } ? ? ? ? } ? ? ? ? System.out.println("班級有:" + total + "人"); ? ? ? ? System.out.println("班級男生有:" + count + "人"); ? ? ? ? System.out.println("班級女生有:" + (total - count) + "人"); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot+Jpa項(xiàng)目配置雙數(shù)據(jù)源的實(shí)現(xiàn)
本文主要介紹了SpringBoot+Jpa項(xiàng)目配置雙數(shù)據(jù)庫源的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12Spring boot 總結(jié)之跨域處理cors的方法
本篇文章主要介紹了Spring boot 總結(jié)之跨域處理cors的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02解決@PathVariable出現(xiàn)點(diǎn)號.時(shí)導(dǎo)致路徑參數(shù)截?cái)喃@取不全的問題
這篇文章主要介紹了解決@PathVariable出現(xiàn)點(diǎn)號.時(shí)導(dǎo)致路徑參數(shù)截?cái)喃@取不全的問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08slf4j?jcl?jul?log4j1?log4j2?logback各組件系統(tǒng)日志切換
這篇文章主要介紹了slf4j、jcl、jul、log4j1、log4j2、logback的大總結(jié),各個(gè)組件的jar包以及目前系統(tǒng)日志需要切換實(shí)現(xiàn)方式的方法,有需要的朋友可以借鑒參考下2022-03-03SpringCloud?Nacos?+?Ribbon?調(diào)用服務(wù)的實(shí)現(xiàn)方式(兩種)
這篇文章主要介紹了SpringCloud?Nacos?+?Ribbon?調(diào)用服務(wù)的兩種方法,分別是通過代碼的方式調(diào)用服務(wù)和通過注解方式調(diào)用服務(wù),每種方式給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03Java創(chuàng)建,編輯與刪除Excel迷你圖表的實(shí)現(xiàn)方法
迷你圖是Excel工作表單元格中表示數(shù)據(jù)的微型圖表。本文將通過Java代碼示例介紹如何在Excel中創(chuàng)建迷你圖表,以及編輯和刪除表格中的迷你圖表,需要的可以參考一下2022-05-05