欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java實(shí)現(xiàn)學(xué)生教師管理系統(tǒng)

 更新時(shí)間:2020年10月29日 09:20:50   作者:Zyt119977  
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)學(xué)生教師管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java實(shí)現(xiàn)學(xué)生教師管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

類設(shè)計(jì)

1.1 父類抽象類

  • 成員屬性: id(編號(hào)) name(姓名) sex(性別) birthday(生日) age(年齡-由生日計(jì)算得出)
  • 構(gòu)造方法: 無參構(gòu)造 全參構(gòu)造 成員方法: toString()
  • 抽象方法: getType():由各子類實(shí)現(xiàn),返回各自的"類型"字符串。 getWork():由各子類實(shí)現(xiàn),返回各自的"工作"字符串。

1.2 子類Student

  • 構(gòu)造方法 無參構(gòu)造 全參構(gòu)造(super調(diào)用父類全參構(gòu)造)
  • 重寫抽象方法 重寫getType() 重寫getWork()

1.3 子類Teacher

  • 構(gòu)造方法 無參構(gòu)造 全參構(gòu)造(super調(diào)用父類全參構(gòu)造)
  • 重寫抽象方法 重寫getType() 重寫getWork()

1.4 工具類

  • 全局變量 學(xué)員ID值(添加學(xué)員信息時(shí),編號(hào)由此ID加1生成)
  • 教師ID值(添加教師信息時(shí),編號(hào)由此ID加1生成)
  • 全局方法 根據(jù)生日計(jì)算年齡的方法 打印一個(gè)Person對(duì)象的方法;
  • 打印一個(gè)ArrayList<? extends Person>集合的方法

1.5 啟動(dòng)類

定義啟動(dòng)類:MainApp啟動(dòng)程序

程序設(shè)計(jì)

2.1 父類Person類

/*
成員屬性有id 名字 性別 年齡 生日 和年齡
成員方法有描述自己的職位和工作
*/
public abstract class Person {
 private int id;
 private String name;
 private String gender;
 private String birthday;
 private int age;

 public Person() {
 }

 public Person(int id, String name, String gender, String birthday) {
  this.id = id;
  this.name = name;
  this.gender = gender;
  this.birthday = birthday;

 }

 public abstract String getType();

 public abstract String getWork();

 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 String getGender() {
  return gender;
 }
 public void setGender(String gender) {
  this.gender = gender;
 }
 public String getBirthday() {
  return birthday;
 }
 public void setBirthday(String birthday) {
  this.birthday = birthday;
 }
 //getAge需要接收的數(shù)據(jù)需要通過Utils的birthday方法進(jìn)行計(jì)算
 public int getAge() {
  age = Utils.birthday(this.getBirthday());
  return age;
 }
 public void setAge(int age) {
  this.age = age;
 }
 @Override
 public String toString() {
  return   id + "\t\t" +
      name + "\t\t" +
      gender + "\t\t" +
      birthday + "\t" +
      this.getAge() + "\t\t" +
      "我是一名" + getType() + "我的工作是" + getWork();
 }
}

2.2 學(xué)生類

/*
重寫父類方法
*/
public class Stuent extends Person {
 public Stuent() {
 }

 public Stuent(int id, String name, String gender, String birthday) {
  super(id, name, gender, birthday);
 }

 @Override
 public String getType() {
  return "學(xué)習(xí)Java";
 }

 @Override
 public String getWork() {
  return "學(xué)生";
 }
}

2.3 老師類

/*
重寫父類方法
*/
public class Teacher extends Person {
 public Teacher() {
 }

 public Teacher(int id, String name, String gender, String birthday) {
  super(id, name, gender, birthday);
 }

 @Override
 public String getType() {
  return "教師";
 }

 @Override
 public String getWork() {
  return "講課";
 }
}

2.4 工具類

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
/*
學(xué)員ID值(添加學(xué)員信息時(shí),編號(hào)由此ID加1生成)
教師ID值(添加教師信息時(shí),編號(hào)由此ID加1生成)
全局方法
根據(jù)生日計(jì)算年齡的方法 打印一個(gè)Person對(duì)象的方法;
 打印一個(gè)ArrayList<? extends Person>集合的方法;
 */
public class Utils {
 public static int stuID;
 public static int teaID;
 public static int birthday(String birthday) {
  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  Date birthdayDate =null;
  try {birthdayDate = sdf.parse(birthday);
  } catch (ParseException e) { return -1;
  //輸入的日期不符合模式,返回-1  
  }
  //創(chuàng)建生日日歷對(duì)象
  Calendar c = Calendar.getInstance();
  //求出生日時(shí)間傳給日歷對(duì)象
  c.setTime(birthdayDate);
  //求出生日年份
  c.get(Calendar.YEAR);
  //創(chuàng)建檔當(dāng)前時(shí)間的日歷對(duì)象
  Calendar c1 = Calendar.getInstance();
  c1.get(Calendar.MONTH);
  if (c1.before(c)) {
   return -1;
  }
  //判斷月份大小
  if (c.get(Calendar.MONTH) > c1.get(Calendar.MONTH)) {
   return c1.get(Calendar.YEAR) - c.get(Calendar.YEAR) - 1;
  } else if (c.get(Calendar.MONTH) < c1.get(Calendar.MONTH)) {
   return c1.get(Calendar.YEAR) - c.get(Calendar.YEAR);
  } else{
   //判斷日期大小
   if (c.get(Calendar.DAY_OF_MONTH) > c1.get(Calendar.DAY_OF_MONTH)) {
    return c1.get(Calendar.YEAR) - c.get(Calendar.YEAR) - 1;
   } else if (c.get(Calendar.DAY_OF_MONTH) < c1.get(Calendar.DAY_OF_MONTH)) {
    return c1.get(Calendar.YEAR) - c.get(Calendar.YEAR);
   } else{
    //今天過生日默認(rèn)增加一歲
    return c1.get(Calendar.YEAR) - c.get(Calendar.YEAR);
   }
  }
 }
 //打印ArrayList的方法
 public static void PersonList(ArrayList<? extends Person> personlist) {
  System.out.println("***************************************************");
  System.out.println("編號(hào)\t\t姓名\t\t性別\t\t生日\t\t\t年齡\t\t描述");
  for (int i = 0; i < personlist.size(); i++) {
   System.out.println(personlist.get(i));
  }
 }
 //打印Person的方法
 public static void printPerson(Person person) {
  System.out.println("***************************************************");
  System.out.println("編號(hào)\t\t姓名\t\t性別\t\t生日\t\t\t年齡\t\t描述");
  System.out.println(person);
 }
}

2.5 啟動(dòng)類

import java.util.ArrayList;
import java.util.Scanner;

public class MainApp {
 public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);

  //學(xué)生集合
  ArrayList<Stuent> stuents = new ArrayList<>();
  //老師集合
  ArrayList<Teacher> teachers = new ArrayList<>();

  while (true) {
   System.out.println("1.學(xué)員信息管理 2.教師信息管理 3.退出");
   int a = sc.nextInt();
   switch (a) {
    case 1:
     studentManage(stuents, sc);
     break;
    case 2:
     teacherManage(teachers, sc);
     break;
    case 3:
     System.out.println("謝謝使用");
     System.exit(0);
    default:
     System.out.println("輸入有誤");
     break;
   }
  }

 }
 //教師二級(jí)列表
 private static void teacherManage(ArrayList<Teacher> teachers, Scanner sc) {
  while (true) {
   System.out.println("教師管理系統(tǒng)");
   System.out.println("1.添加教師信息 2.修改教師信息 3.刪除教師信息 4.查詢教師 5.返回");
   int a = sc.nextInt();
   switch (a) {
    case 1:
     addTeacher(teachers, sc);
     break;
    case 2:
     updateTeacher(teachers, sc);
     break;
    case 3:
     delTeacher(teachers, sc);
     break;
    case 4:
     findTeacher(teachers);
     break;
    case 5:
     return;
   }
  }
 }
 //教師添加
 private static void addTeacher(ArrayList<Teacher> teachers, Scanner sc) {
  System.out.println("輸入姓名");
  String name = sc.next();
  System.out.println("輸入性別");
  String gender = sc.next();
  System.out.println("輸入生日");
  String birthday = sc.next();
  teachers.add(new Teacher(++Utils.teaID, name, gender, birthday));
  System.out.println("添加成功");
 }
 //修改教師信息
 private static void updateTeacher(ArrayList<Teacher> teachers, Scanner sc) {
  System.out.println("請(qǐng)輸入要改教師的id");
  int updateid = sc.nextInt();
  for (int i = 0; i < teachers.size(); i++) {
   Teacher tea = teachers.get(i);
   if (tea.getId() == updateid) {
    Utils.printPerson(tea);
    System.out.println("其輸入新的姓名(保留輸入0)");
    String newName = sc.next();
    System.out.println("輸入新的性別(保留輸入0)");
    String newGender = sc.next();
    System.out.println("輸入新的生日(保留輸入0)");
    String newbirthday = sc.next();

    if (!"0".equals(newName)) {
     tea.setName(newName);
    }
    if (!"0".equals(newGender)) {
     tea.setGender(newGender);
    }
    if (!"0".equals(newbirthday)) {
     tea.setBirthday(newbirthday);
    }
    System.out.println("修改成功");
    return;
   }
  }
  System.out.println("沒有找到" + updateid + "id");
 }
 //刪除教師信息
 private static void delTeacher(ArrayList<Teacher> teachers, Scanner sc) {

  System.out.println("請(qǐng)輸入要?jiǎng)h除學(xué)教師的的id");
  int delid = sc.nextInt();
  for (int i = 0; i < teachers.size(); i++) {
   Teacher tea = teachers.get(i);
   //
   if (delid == tea.getId()) {
    //輸出要?jiǎng)h除的信息
    Utils.printPerson(tea);
    //判斷是否要?jiǎng)h除信息
    System.out.println("是否要?jiǎng)h除這條信息(y/n)");
    String input = sc.next();
    if ("y".equals(input)) {
     teachers.remove(i);
     System.out.println("刪除成功");
     return;
    } else if ("n".equals(input)) {
     System.out.println("操作被取消");
     return;
    }
   }
  }
  System.out.println("沒有找到id為" + delid + "的成員");
 }
 //查詢教師信息
 private static void findTeacher(ArrayList<Teacher> teachers) {
  if (teachers.size() == 0) {
   System.out.println("查詢不到數(shù)據(jù)");
  } else {
    Utils.PersonList(teachers);
  }
 }

 //學(xué)生二級(jí)列表
 private static void studentManage(ArrayList<Stuent> stuents, Scanner sc) {
  while (true) {
   System.out.println("學(xué)生管理系統(tǒng)");
   System.out.println("1.添加學(xué)員 2.修改學(xué)員 3.刪除學(xué)員 4.查詢學(xué)員 5.返回");
   int a = sc.nextInt();
   switch (a) {
    case 1:
     addStudent(stuents, sc);
     break;
    case 2:
     updateStudent(stuents, sc);
     break;
    case 3:
     delStudent(stuents, sc);
     break;
    case 4:
     findStudent(stuents);
     break;
    case 5:
     return;
   }
  }
 }
 //添加學(xué)生信息
 private static void addStudent(ArrayList<Stuent> stuents, Scanner sc) {
  System.out.println("輸入姓名");
  String name = sc.next();
  System.out.println("輸入性別");
  String gender = sc.next();
  System.out.println("輸入生日");
  String birthday = sc.next();
  stuents.add(new Stuent(++Utils.stuID, name, gender, birthday));
  System.out.println("添加成功");
 }
 //修改學(xué)生信息
 private static void updateStudent(ArrayList<Stuent> stuents, Scanner sc) {
  System.out.println("請(qǐng)輸入要改學(xué)生的id");
  int updateid = sc.nextInt();
  for (int i = 0; i < stuents.size(); i++) {
   Stuent stu = stuents.get(i);
   if (stu.getId() == updateid) {
    Utils.printPerson(stu);
    System.out.println("其輸入新的姓名(保留輸入0)");
    String newName = sc.next();
    System.out.println("輸入新的性別(保留輸入0)");
    String newGender = sc.next();
    System.out.println("輸入新的生日(保留輸入0)");
    String newbirthday = sc.next();

    if (!"0".equals(newName)) {
     stu.setName(newName);
    }
    if (!"0".equals(newGender)) {
     stu.setGender(newGender);
    }
    if (!"0".equals(newbirthday)) {
     stu.setBirthday(newbirthday);
    }
    System.out.println("修改成功");
    return;
   }
  }
  System.out.println("沒有找到" + updateid + "id");
 }
 //刪除學(xué)生信息
 private static void delStudent(ArrayList<Stuent> stuents, Scanner sc) {
  System.out.println("請(qǐng)輸入要?jiǎng)h除學(xué)生的的學(xué)號(hào)");
  int delid = sc.nextInt();
  for (int i = 0; i < stuents.size(); i++) {
   Stuent stu = stuents.get(i);
   //
   if (delid == stu.getId()) {
    //輸出要?jiǎng)h除的信息
    Utils.printPerson(stu);
    //判斷是否要?jiǎng)h除信息
    System.out.println("是否要?jiǎng)h除這條信息(y/n)");
    String input = sc.next();
    if ("y".equals(input)) {
     stuents.remove(i);
     System.out.println("刪除成功");
     return;
    } else if ("n".equals(input)) {
     System.out.println("操作被取消");
     return;
    }
   }
  }
  System.out.println("沒有找到id為" + delid + "的成員");
 }
 //查找學(xué)生信息
 private static void findStudent(ArrayList<Stuent> stuents) {
  System.out.println("查詢結(jié)果");
  if (stuents.size() == 0) {
   System.out.println("沒有數(shù)據(jù)");
  } else {
   Utils.PersonList(stuents);
  }
 }

}

更多學(xué)習(xí)資料請(qǐng)關(guān)注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 解決springboot項(xiàng)目啟動(dòng)報(bào)錯(cuò)Error creating bean with name dataSourceScriptDatabaseInitializer問題

    解決springboot項(xiàng)目啟動(dòng)報(bào)錯(cuò)Error creating bean with&nb

    這篇文章主要介紹了解決springboot項(xiàng)目啟動(dòng)報(bào)錯(cuò)Error creating bean with name dataSourceScriptDatabaseInitializer問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助
    2024-03-03
  • Maven的配置文件pom.xml詳解(含常用plugin)

    Maven的配置文件pom.xml詳解(含常用plugin)

    pom.xml是Maven項(xiàng)目的核心配置文件,它是 項(xiàng)目對(duì)象模型 - Project Object Model(POM)的縮寫,本文我們將全面解析pom.xml,了解其結(jié)構(gòu)和屬性,以及如何使用它來管理項(xiàng)目,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • MyBatis核心配置文件深入分析

    MyBatis核心配置文件深入分析

    這篇文章主要介紹了MyBatis核心配置文件,MyBatis的前身就是iBatis,iBatis本是由Clinton Begin開發(fā),后來捐給Apache基金會(huì),成立了iBatis開源項(xiàng)目。2010年5月該項(xiàng)目由Apahce基金會(huì)遷移到了Google Code,并且改名為MyBatis
    2022-12-12
  • Java使用POI生成Word文檔簡單代碼示例

    Java使用POI生成Word文檔簡單代碼示例

    Java?POI是一個(gè)用于操作Microsoft?Office格式文件的Java庫,包括?Word、Excel和PowerPoint等文件,這篇文章主要給大家介紹了關(guān)于Java使用POI生成Word文檔的相關(guān)資料,需要的朋友可以參考下
    2024-08-08
  • SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法

    SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法

    這篇文章主要介紹了SpringBoot項(xiàng)目application.yml文件數(shù)據(jù)庫配置密碼加密的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-03-03
  • Spring中最常用的注解之一@Autowired詳解

    Spring中最常用的注解之一@Autowired詳解

    本文講解了Spring中最常用的注解之一@Autowired, 平時(shí)我們可能都是使用屬性注入的,但是后續(xù)建議大家慢慢改變習(xí)慣,使用構(gòu)造器注入。同時(shí)也講解了這個(gè)注解背后的實(shí)現(xiàn)原理,需要的朋友可以參考下
    2023-01-01
  • Java設(shè)計(jì)模式之橋接模式實(shí)例詳解

    Java設(shè)計(jì)模式之橋接模式實(shí)例詳解

    這篇文章主要介紹了Java設(shè)計(jì)模式之橋接模式,結(jié)合實(shí)例形式詳細(xì)分析了橋接模式的概念、功能、Java實(shí)現(xiàn)方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-09-09
  • Elasticsearch?Recovery索引分片分配詳解

    Elasticsearch?Recovery索引分片分配詳解

    這篇文章主要為大家介紹了關(guān)于Elasticsearch的Recovery索引分片分配詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>
    2022-04-04
  • Netty搭建WebSocket服務(wù)器實(shí)戰(zhàn)教程

    Netty搭建WebSocket服務(wù)器實(shí)戰(zhàn)教程

    這篇文章主要介紹了Netty搭建WebSocket服務(wù)器實(shí)戰(zhàn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-03-03
  • Java中的functor實(shí)現(xiàn)

    Java中的functor實(shí)現(xiàn)

    Java中的functor實(shí)現(xiàn)...
    2006-12-12

最新評(píng)論