<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
本文範例為大家分享了Java實現學生教師管理系統的具體程式碼,供大家參考,具體內容如下
我們可以通過管理系統對學生和教師進行管理
物件學生和教師進行增刪改查等的功能
1、Student和Teacher的父類別
2、Student類
3、Teacher類
4、Utils工具類
5、測試類
Student和Teacher的父類別
public class Person { private String id; // 編號 private String name; // 姓名 private String IDcard; // 身份證 private String sex; // 性別 private String birthday; // 生日 private int age; //年齡 private String site; //地址 private String phone; // 電話 public Person() { } public Person(String id, String name, String IDcard, String sex, String birthday, String site, String phone) throws ParseException { this.id = id; this.name = name; this.IDcard = IDcard; this.sex = sex; this.birthday = birthday; this.age = Utils.birthdayToAge(birthday); this.site = site; this.phone = phone; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getIDcard() { return IDcard; } public void setIDcard(String IDcard) { this.IDcard = IDcard; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) throws ParseException { this.birthday = birthday; this.age = Utils.birthdayToAge(birthday); } public int getAge() { return age; } public String getSite() { return site; } public void setSite(String site) { this.site = site; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } }
Student類
import java.text.ParseException; public class Student extends Person { private int grade; // 成績 private String group; // 班級 // 學生號,姓名,身份證,性別,生日,地址,手機號,成績,班級 public Student(String id, String name, String IDcard, String sex, String birthday, String site, String phone, int grade, String group) throws ParseException { super(id, name, IDcard, sex, birthday, site, phone); this.grade = grade; this.group = group; } public Student() { } public int getGrade() { return grade; } public void setGrade(int grade) { this.grade = grade; } public String getGroup() { return group; } public void setGroup(String group) { this.group = group; } }
Teacher類
import java.text.ParseException; public class Teacher extends Person{ private String career; // 專業 private String salary; // 工資 // 教師號,姓名,身份證,性別,生日,地址,手機號,專業,工資 public Teacher(String id, String name, String IDcard, String sex, String birthday, String site, String phone, String career, String salary) throws ParseException { super(id, name, IDcard, sex, birthday, site, phone); this.career = career; this.salary = salary; } public Teacher() { } public String getCareer() { return career; } public void setCareer(String career) { this.career = career; } public String getSalary() { return salary; } public void setSalary(String salary) { this.salary = salary; } }
根據生日計算年齡的一個靜態工具類
Utils
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Utils { public static int birthdayToAge(String birthday) throws ParseException { SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); Date date = sdf.parse(birthday); Date date1 = new Date(); long time = date.getTime(); long time1 = date1.getTime(); long age = (time1 - time) / 1000 / 60 / 60/ 24 / 365; return (int)age; } }
測試類
import java.text.ParseException; import java.util.ArrayList; import java.util.Scanner; public class StudentAndTeacherSystem { public static Scanner sc = new Scanner(System.in); public static ArrayList<Student> students = new ArrayList(); public static ArrayList<Teacher> teachers = new ArrayList(); public static void main(String[] args) throws ParseException { System.out.println("********************歡迎來到學生教師管理系統********************"); while (true) { System.out.println("【1】 學生管理系統 【2】 教師管理系統 【3】 退出"); String num = sc.next(); switch (num) { case "1": // 學生管理系統 studentSystem(); break; case "2": // 教師管理系統 teacherSystem(); break; case "3": System.out.println("感謝您的使用!"); System.exit(0); default: System.out.println("您輸入的編號" + num + "有誤!"); break; } } } // 學生 public static void studentSystem() throws ParseException { System.out.println("**********************【歡迎來到學生管理系統】**********************"); while (true){ System.out.println("*******【1】新增學生***************************【2】 修改學生*********"); System.out.println("*******【3】刪除學生***************************【4】 檢視所有學生******"); System.out.println("*******【5】查詢指定學生************************【6】 統計所有學生資訊**"); System.out.println("***************************【7】 返回上一級***************************"); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~【請輸入您要選擇的編號】~~~~~~~~~~~~~~~~~~~~~~~~"); String num = sc.next(); switch (num){ case "1": // 新增 addStudent(); break; case "2": // 修改 updateStudent(); break; case "3": // 刪除 deleteStudent(); break; case "4": // 檢視 selectStudent(); break; case "5": // 指定檢視 assignStudent(); break; case "6": // 統計 statisticsStudent(); break; case "7": System.out.println("返回上一級"); return; default: System.out.println("您輸入的編號" + num + "有誤!"); break; } } } public static void addStudent() throws ParseException { // System.out.println("新增成功!"); System.out.println("請輸入您的學生號:"); while (true) { String id = sc.next(); int index = getIndex(students, id); if (index == -1) { System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入您的身份證:"); String IDcard = sc.next(); System.out.println("請輸入您的性別:"); String sex = sc.next(); System.out.println("請輸入您的生日(格式:2000-10-10)"); String birthday = sc.next(); System.out.println("請輸入您的家庭地址:"); String site = sc.next(); System.out.println("請輸入您的手機號:"); String phone = sc.next(); System.out.println("請輸入您的成績:"); int grade = sc.nextInt(); System.out.println("請輸入您的班級:"); String group = sc.next(); Student stu = new Student(id, name, IDcard, sex, birthday, site, phone, grade, group); students.add(stu); System.out.println("新增成功!"); return; } else { System.out.println("您輸入的學生號已存在,請重新輸入!"); } } } // 修改 public static void updateStudent() throws ParseException { // System.out.println("修改成功!"); System.out.println("請輸入您要修改的學生號:"); String id = sc.next(); int index = getIndex(students,id); if(index == -1){ System.out.println("您輸入的學生號不存在!!"); return; } System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入您的身份證:"); String IDcard = sc.next(); System.out.println("請輸入您的性別:"); String sex = sc.next(); System.out.println("請輸入您的生日:"); String birthday = sc.next(); System.out.println("請輸入您的地址:"); String site = sc.next(); System.out.println("請輸入您的手機號:"); String phone = sc.next(); System.out.println("請輸入您的成績:"); int grade = sc.nextInt(); System.out.println("請輸入您的班級:"); String group = sc.next(); Student stu = new Student(id,name, IDcard,sex,birthday,site,phone,grade,group); students.set(index,stu); System.out.println("修改成功!"); } // 刪除 public static void deleteStudent() { // System.out.println("刪除成功!"); System.out.println("請輸入您要刪除的學生號:"); String id = sc.next(); int index = getIndex(students,id); if(index == -1){ System.out.println("您輸入的學生號不存在!"); return; }else{ students.remove(index); System.out.println("刪除成功!"); return; } } // 檢視 public static void selectStudent() { // System.out.println("檢視成功!"); int num = students.size(); if(num == 0){ System.out.println("暫無資訊,請新增以後在來檢視!"); return; } // 編號,姓名,身份證,性別,生日,地址,手機號,成績,班級 System.out.println("學生號t姓名t身份證t性別t生日t年齡t地址t手機號t成績t班級"); for (int i = 0; i < students.size(); i++) { Student stu = students.get(i); System.out.println(stu.getId() + "t" + stu.getName() + "t" + stu.getIDcard() + "t" + stu.getSex() + "t" + stu.getBirthday() + "t" + stu.getAge() + "t" + stu.getSite() + "t" + stu.getPhone() + "t" + stu.getGrade() + "t" + stu.getGroup()); } } // 指定檢視 public static void assignStudent() { // System.out.println("指定檢視成功!"); System.out.println("請輸入您要查詢的學生號:"); String id = sc.next(); int index = getIndex(students,id); if(index == -1){ System.out.println("您輸入的學生號不存在!"); }else{// // 編號,姓名,身份證,性別,生日,地址,手機號,成績,班級 for (int i = 0; i < students.size(); i++) { Student stu = students.get(i); System.out.println("學生號:" + stu.getId()); System.out.println("姓 名:" + stu.getName()); System.out.println("生 日:" + stu.getBirthday()); System.out.println("年 齡:" + stu.getAge()); System.out.println("身份證:" + stu.getIDcard()); System.out.println("性 別:" + stu.getSex()); System.out.println("地 址:" + stu.getSite()); System.out.println("手機號:" + stu.getPhone()); System.out.println("成 績:" + stu.getGrade()); System.out.println("班 級:" + stu.getGroup()); } } } // 統計 public static void statisticsStudent() { // System.out.println("統計成功!"); int countSex = 0; int countGrade = 0; for (int i = 0; i < students.size(); i++) { Student stu = students.get(i); if(stu.getSex().equals("男")){ countSex++; } if(stu.getGrade() > 60){ countGrade++; } } System.out.println("學校一共有:" + students.size() + "個人"); System.out.println("男生有:" + countSex + "人"); System.out.println("女生有:" + (students.size() - countSex) + "人"); System.out.println("及格有:" + countGrade + "人"); System.out.println("不及格有:" + (students.size() - countGrade) + "人"); } // 判斷學生是否存在 public static int getIndex(ArrayList<Student> students,String id){ int index = -1; for (int i = 0; i < students.size(); i++) { Student stu = students.get(i); String sid = stu.getId(); if(sid.equals(id)){ index = i; } } return index; } //=================================================================================== // 教師 public static void teacherSystem() throws ParseException { System.out.println("********************【歡迎來到教師管理系統】**************************"); while (true){ System.out.println("*******【1】新增教師***************************【2】 修改教師*********"); System.out.println("*******【3】刪除教師***************************【4】 檢視所有教師******"); System.out.println("*******【5】查詢指定教師************************【6】 統計所有教師資訊**"); System.out.println("***************************【7】 返回上一級***************************"); System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~【請輸入您要選擇的編號】~~~~~~~~~~~~~~~~~~~~~~~~"); String num = sc.next(); // 編號,姓名,身份證,性別,生日,地址,手機號,成績,班級 switch (num){ case "1": // 新增 addTeacher(); break; case "2": // 修改 updateTeacher(); break; case "3": // 刪除 deleteTeacher(); break; case "4": // 檢視 selectTeacher(); break; case "5": // 指定檢視 assignTeacher(); break; case "6": // 統計 statisticsTeacher(); break; case "7": System.out.println("返回上一級"); return; default: System.out.println("您輸入的編號" + num + "有誤!"); break; } } } // 新增 public static void addTeacher() throws ParseException { //System.out.println("新增成功!"); System.out.println("請輸入您的教師號:"); while (true) { String id = sc.next(); int index = getindex(teachers, id); if (index == -1) { System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入您的身份證:"); String IDcard = sc.next(); System.out.println("請輸入您的性別:"); String sex = sc.next(); System.out.println("請輸入您的生日(格式:2000-10-10)"); String birthday = sc.next(); System.out.println("請輸入您的家庭地址:"); String site = sc.next(); System.out.println("請輸入您的手機號:"); String phone = sc.next(); System.out.println("請輸入您的專業:"); String career = sc.next(); System.out.println("請輸入您的工資:"); String salary = sc.next(); Teacher teacher = new Teacher(id, name, IDcard, sex, birthday, site, phone, career, salary); teachers.add(teacher); System.out.println("新增成功!"); return; } else { System.out.println("您輸入的教師號已存在,請重新輸入!"); } } } // 修改 public static void updateTeacher() throws ParseException { //System.out.println("修改成功!"); System.out.println("請輸入您要修改的教師號:"); String id = sc.next(); int index = getindex(teachers,id); if(index == -1){ System.out.println("您輸入的教師號不存在!!"); return; } System.out.println("請輸入您的姓名:"); String name = sc.next(); System.out.println("請輸入您的身份證:"); String IDcard = sc.next(); System.out.println("請輸入您的性別:"); String sex = sc.next(); System.out.println("請輸入您的生日:"); String birthday = sc.next(); System.out.println("請輸入您的地址:"); String site = sc.next(); System.out.println("請輸入您的手機號:"); String phone = sc.next(); System.out.println("請輸入您的專業:"); String career = sc.next(); System.out.println("請輸入您的工資:"); String salary = sc.next(); Teacher teacher = new Teacher(id,name, IDcard,sex,birthday,site,phone,career,salary); teachers.set(index,teacher); System.out.println("修改成功!"); } // 刪除 public static void deleteTeacher() { //System.out.println("刪除成功!"); System.out.println("請輸入您要刪除的教師號:"); String id = sc.next(); int index = getindex(teachers,id); if(index == -1){ System.out.println("您輸入的教師號不存在!"); return; }else{ teachers.remove(index); System.out.println("刪除成功!"); return; } } // 檢視 public static void selectTeacher() { //System.out.println("檢視成功!"); int num = teachers.size(); if(num == 0){ System.out.println("暫無資訊,請新增以後在來檢視!"); return; } // 編號,姓名,身份證,性別,生日,地址,手機號,成績,班級 System.out.println("教師號t姓名t身份證t性別t生日t年齡t地址t手機號t專業t工資"); for (int i = 0; i < teachers.size(); i++) { Teacher teacher = teachers.get(i); System.out.println(teacher.getId() + "t" + teacher.getName() + "t" + teacher.getIDcard() + "t" + teacher.getSex() + "t" + teacher.getBirthday() + "t" + teacher.getAge() + "t" + teacher.getSite() + "t" + teacher.getPhone() + "t" + teacher.getCareer() + "t" + teacher.getSalary()); } } // 指定檢視 public static void assignTeacher() { //System.out.println("指定檢視成功!"); System.out.println("請輸入您要查詢的教師號:"); String id = sc.next(); int index = getindex(teachers,id); if(index == -1){ System.out.println("您輸入的教師號不存在!"); }else{// // 編號,姓名,身份證,性別,生日,地址,手機號,成績,班級 for (int i = 0; i < teachers.size(); i++) { Teacher teacher = teachers.get(i); System.out.println("教師號:" + teacher.getId()); System.out.println("姓 名:" + teacher.getName()); System.out.println("生 日:" + teacher.getBirthday()); System.out.println("年 齡:" + teacher.getAge()); System.out.println("身份證:" + teacher.getIDcard()); System.out.println("性 別:" + teacher.getSex()); System.out.println("地 址:" + teacher.getSite()); System.out.println("手機號:" + teacher.getPhone()); System.out.println("專 業:" + teacher.getCareer()); System.out.println("工 資:" + teacher.getCareer()); } } } // 統計 public static void statisticsTeacher() { // System.out.println("統計成功!"); int countSex = 0; for (int i = 0; i < teachers.size(); i++) { Teacher teacher = teachers.get(i); if(teacher.getSex().equals("男")){ countSex++; } } System.out.println("學校一共有:" + teachers.size() + "個教師"); System.out.println("男教師有:" + countSex + "人"); System.out.println("女教師有:" + (teachers.size() - countSex) + "人"); } // 判斷教師是否存在 public static int getindex(ArrayList<Teacher> teachers,String id){ int index = -1; for (int i = 0; i < teachers.size(); i++) { Teacher teacher = teachers.get(i); String sid = teacher.getId(); if(sid.equals(id)){ index = i; } } return index; } }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援it145.com。
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45