最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java實現(xiàn)人員信息管理系統(tǒng)

 更新時間:2022年02月28日 12:31:57   作者:ZJE_ANDY  
這篇文章主要為大家詳細(xì)介紹了java實現(xiàn)人員信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了java實現(xiàn)人員信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

實現(xiàn)增刪改查.

java入門的練手小程序

1.Person類

package p1;
?
public class Person {
?? ?// Person屬性
?? ?private int num;
?? ?private String name;
?? ?private String sex;
?? ?private int salary;
?
?? ?public Person(int num, String name, String sex, int salary) {
?? ??? ?super();
?? ??? ?this.num = num;
?? ??? ?this.name = name;
?? ??? ?this.sex = sex;
?? ??? ?this.salary = salary;
?? ?}
?
?? ?// 對Perosn操作的方法
?? ?public int getNum() {
?? ??? ?return num;
?? ?}
?
?? ?public void setNum(int num) {
?? ??? ?this.num = num;
?? ?}
?
?? ?public String getName() {
?? ??? ?return name;
?? ?}
?
?? ?public void setName(String name) {
?? ??? ?this.name = name;
?? ?}
?
?? ?public String getSex() {
?? ??? ?return sex;
?? ?}
?
?? ?public void setSex(String sex) {
?? ??? ?this.sex = sex;
?? ?}
?
?? ?public int getSalary() {
?? ??? ?return salary;
?? ?}
?
?? ?public void setSalary(int salary) {
?? ??? ?this.salary = salary;
?? ?}
?
}

2.SysMenu類

package p1;
?
public class SysMenu {
?? ?public static final String[] MENU = { "1.員工信息管理", "2.退出" };
?? ?public static final String[] OPERATION_MENU = { "1.新增", "2.查看", "3.修改", "4.刪除", "5.返回" };
?
?? ?public static void showMenu(String[] Menu) {
?? ??? ?for (int i = 0; i < Menu.length; i++)
?? ??? ??? ?System.out.print(Menu[i] + "\t\t");
?? ??? ?System.out.println();
?? ??? ?System.out.println("---------------------------------------");
?? ?}
}

3.SysInfo類

package p1;
?
import java.util.ArrayList;
import java.util.List;
?
public class SysInfo {
?? ?private static List informationList = new ArrayList();
?
?? ?// 獲取 informationList
?? ?public static List getList() {
?? ??? ?return informationList;
?? ?}
}

4.InformationService類

package p1;
?
import java.util.List;
?
public class InformationService {
?? ?private List informationList = SysInfo.getList();
?
?? ?// 獲取信息列表
?? ?public List getList() {
?? ??? ?return informationList;
?? ?}
?
?? ?// 按編號查找信息
?? ?public Person getPersonByNum(final int num) {
?? ??? ?if (num < 1) {
?? ??? ??? ?System.out.println("編號錯誤");
?? ??? ??? ?return null;
?? ??? ?}
?
?? ??? ?for (int i = 0; i < informationList.size(); i++) {
?? ??? ??? ?Person p = (Person) informationList.get(i);
?? ??? ??? ?if (p.getNum() == num) {
?? ??? ??? ??? ?System.out.println("查找成功");
?? ??? ??? ??? ?return p;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?System.out.println("查找失敗");
?? ??? ?return null;
?? ?}
?
?? ?//查看單一Person信息
?? ?public void showAPerson(Person p)
?? ?{
?? ??? ?System.out.println("編號\t\t姓名\t\t性別\t\t薪水");
?? ??? ?System.out.println(p.getNum()+ "\t\t" + p.getName() + "\t\t" + p.getSex() + "\t\t" + p.getSalary());
?? ?}
?? ?//show all Person
?? ?public void showPerson() {
?? ??? ?System.out.println("編號\t\t姓名\t\t性別\t\t薪水");
?
?? ??? ?List ps = getList();
?? ??? ?for (int i = 0; i < ps.size(); i++) {
?? ??? ??? ?Person p = (Person) ps.get(i);
?? ??? ??? ?System.out.println(p.getNum() + "\t\t" + p.getName() + "\t\t" + p.getSex() + "\t\t" + p.getSalary());
?? ??? ?}
?? ?}
?
?? ?
?? ?// 按名字查找信息
?? ?public Person getPersonByName(final String name) {
?? ??? ?if (name == null)
?? ??? ??? ?return null;
?? ??? ?for (int i = 0; i < informationList.size(); i++) {
?? ??? ??? ?Person p = (Person) informationList.get(i);
?? ??? ??? ?if (p.getName().equals(name)) {
?? ??? ??? ??? ?return p;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return null;
?? ?}
?? ?
?? ?//檢查對象是否存在
?? ?public boolean CheckExitByNum(int num)
?? ?{
?? ??? ?for(int i=0;i<informationList.size();i++)
?? ??? ?{
?? ??? ??? ?Person p = (Person)informationList.get(i);
?? ??? ??? ?if(p.getNum()==num)
?? ??? ??? ??? ?return true;
?? ??? ?}
?? ??? ?return false;
?? ?}
?? ?
?? ?//save Person
?? ?public void savePerson(Person p)
?? ?{
?? ??? ?p.setNum(getPersonMaxInt()+1);
?? ??? ?informationList.add(p);
?? ?}
?? ?
?? ?// 查找最大編號
?? ?public int getPersonMaxInt()
?? ?{
?? ??? ?int max = 0;
?? ??? ?for(int i =0;i<informationList.size();i++)
?? ??? ?{
?? ??? ??? ?Person p =(Person)informationList.get(i);
?? ??? ??? ?if(max < p.getNum())
?? ??? ??? ??? ?max = p.getNum();
?? ??? ?}
?? ??? ?return max;
?? ?}
}

5.SysRun類

package p1;
?
import java.util.InputMismatchException;
import java.util.List;
import java.util.Scanner;
?
public class SysRun {
?? ?private List informationList = SysInfo.getList();
?? ?private Scanner s = new Scanner(System.in);
?? ?private InformationService is = new InformationService();
?
?? ?// 系統(tǒng)運行類
?? ?public static void main(String[] args) {
?? ??? ?SysRun sys = new SysRun();
?? ??? ?sys.sysRun();
?? ?}
?
?? ?public void sysRun() {
?? ??? ?System.out.println("啟動系統(tǒng)管理系統(tǒng)");
?? ??? ?boolean isExit = false;
?? ??? ?do {
?? ??? ??? ?System.out.println("----------操作選項-------------");
?? ??? ??? ?SysMenu.showMenu(SysMenu.MENU);
?? ??? ??? ?// 獲取用戶輸入
?? ??? ??? ?int operNum = getCorrONum(SysMenu.MENU);
?? ??? ??? ?// 管理操作
?? ??? ??? ?isExit = doManageNum(operNum);
?? ??? ?} while (!isExit);
?? ??? ?System.out.println("系統(tǒng)退出.");
?? ?}
?
?? ?private boolean doManageNum(int operNum) {
?? ??? ?boolean isExit = false;
?? ??? ?switch (operNum) {
?? ??? ?case 1:
?? ??? ??? ?is.showPerson();
?? ??? ??? ?System.out.println("----------操作選項-------------");
?? ??? ??? ?SysMenu.showMenu(SysMenu.OPERATION_MENU);
?? ??? ??? ?// addPerson();//test
?? ??? ??? ?System.out.println("輸入功能選擇:");
?? ??? ??? ?int num = getVaildInt();
?? ??? ??? ?doOperationNum(num);
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?isExit = true;
?? ??? ??? ?return isExit;
?? ??? ?}
?? ??? ?return isExit;
?? ?}
?
?? ?// doOperationNum
?? ?private void doOperationNum(int OperationNum) {
?? ??? ?// 增,查,修,刪,返回
?? ??? ?switch (OperationNum) {
?? ??? ?case 1:
?? ??? ??? ?// add
?? ??? ??? ?addPerson();
?? ??? ??? ?is.showPerson();
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?// 查看
?? ??? ??? ?viewPerson();
?? ??? ??? ?break;
?? ??? ?case 3:
?? ??? ??? ?updatePerson();
?? ??? ??? ?break;
?? ??? ?case 4:
?? ??? ??? ?deletePerson();
?? ??? ??? ?is.showPerson();
?? ??? ??? ?break;
?? ??? ?case 5:
?? ??? ??? ?break;
?? ??? ?}
?? ?}
?
?? ?// 刪除Person
?? ?private void deletePerson() {
?? ??? ?int num;
?? ??? ?// Person p;
?? ??? ?boolean isOk = false;
?? ??? ?System.out.println("請輸入要刪除信息的編號:");
?? ??? ?do {
?? ??? ??? ?num = getVaildInt();
?? ??? ??? ?isOk = is.CheckExitByNum(num);
?? ??? ??? ?if (isOk == true) {
?? ??? ??? ??? ?System.out.println("編號信息查找成功。");
?? ??? ??? ??? ?informationList.remove(is.getPersonByNum(num));
?? ??? ??? ?} else
?? ??? ??? ??? ?System.out.println("輸入編號有誤,請重新輸入:");
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// 修改Person
?? ?public void updatePerson() {
?? ??? ?System.out.println("請輸入要修改的信息編號:");
?? ??? ?boolean isOk = false;
?? ??? ?Person p;
?? ??? ?do {
?? ??? ??? ?int num = getVaildInt();
?? ??? ??? ?isOk = is.CheckExitByNum(num);
?? ??? ??? ?if (isOk == true) {
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ??? ?p = is.getPersonByNum(num);
?? ??? ??? ??? ?is.showAPerson(p);
?
?? ??? ??? ??? ?System.out.println("請輸入名字:");
?? ??? ??? ??? ?String name = s.next();
?? ??? ??? ??? ?System.out.println("請輸入性別:");
?? ??? ??? ??? ?String sex = getVaildSex();
?? ??? ??? ??? ?System.out.println("請輸入工資:");
?? ??? ??? ??? ?int salary = getVaildInt();
?
?? ??? ??? ??? ?p.setName(name);
?? ??? ??? ??? ?p.setSex(sex);
?? ??? ??? ??? ?p.setSalary(salary);
?? ??? ??? ??? ?is.showPerson();
?? ??? ??? ?} else
?? ??? ??? ??? ?System.out.println("輸入要修改的編號有誤,請重新輸入:");
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// 查看viewPerson()
?? ?private void viewPerson() {
?? ??? ?System.out.println("請輸入要查看的人的信息編號:");
?? ??? ?Person p;
?? ??? ?boolean isOk = false;
?? ??? ?do {
?? ??? ??? ?int num = getVaildInt();
?? ??? ??? ?boolean NumIsOk = is.CheckExitByNum(num);
?? ??? ??? ?if (NumIsOk == true) {
?? ??? ??? ??? ?p = is.getPersonByNum(num);
?? ??? ??? ??? ?is.showAPerson(p);
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ?} else {
?? ??? ??? ??? ?System.out.println("無此編號的人的信息,請重新輸入:");
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// addPerson()
?? ?private void addPerson() {
?? ??? ?System.out.println("------------新增對象---------------");
?
?? ??? ?boolean isOk = false;
?? ??? ?String name = null;
?? ??? ?do {
?? ??? ??? ?System.out.println("請輸入名稱(且不能與現(xiàn)有的對象重名)");
?? ??? ??? ?name = s.next();
?? ??? ??? ?// 處理同名沖突
?? ??? ??? ?if (is.getPersonByName(name) == null) {
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ?} else {
?? ??? ??? ??? ?System.out.println("該人信息已存在,請重新輸入!");
?? ??? ??? ??? ?s.next();
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?? ??? ?// other information
?? ??? ?System.out.println("請輸入其他信息...");
?? ??? ?System.out.println("sex:");
?? ??? ?String sex = getVaildSex();
?? ??? ?System.out.println("salary:");
?? ??? ?int salary = getVaildInt();
?? ??? ?// save
?? ??? ?is.savePerson(new Person(0, name, sex, salary));
?? ?}
?
?? ?/* 輸入有效int */
?? ?private int getVaildInt() {
?? ??? ?int num = 0;
?? ??? ?boolean isOk = false;
?? ??? ?do {
?? ??? ??? ?try {
?? ??? ??? ??? ?num = s.nextInt();
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ?} catch (InputMismatchException e) {
?? ??? ??? ??? ?System.out.println("輸入錯誤,請重新輸入");
?? ??? ??? ??? ?s.next();
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?? ??? ?return num;
?? ?}
?
?? ?/* 輸入有效sex信息 */
?? ?private String getVaildSex() {
?? ??? ?String sex = null;
?? ??? ?boolean isOk = false;
?? ??? ?do {
?? ??? ??? ?sex = s.next();
?? ??? ??? ?if (sex.equals("f") || sex.equals("m"))
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ?else {
?? ??? ??? ??? ?System.out.println("sex輸入讓 有誤,請重新輸入");
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?? ??? ?return sex;
?? ?}
?
?? ?public int getCorrONum(String[] targetMenu) {
?? ??? ?System.out.println("請輸入要選擇的操作:");
?
?? ??? ?int inputNum = 0;
?? ??? ?boolean inputIsOk = false;
?? ??? ?do {
?? ??? ??? ?try {
?? ??? ??? ??? ?inputNum = s.nextInt();
?? ??? ??? ??? ?System.out.println("輸入的是" + inputNum);
?? ??? ??? ??? ?if (inputNum >= 1 && inputNum <= targetMenu.length) {
?? ??? ??? ??? ??? ?inputIsOk = true;
?? ??? ??? ??? ?} else {
?? ??? ??? ??? ??? ?System.out.println("輸入錯誤,請重新輸入!");
?? ??? ??? ??? ?}
?? ??? ??? ?} catch (InputMismatchException e) {
?? ??? ??? ??? ?System.out.println("輸入有誤,請重新輸入");
?? ??? ??? ??? ?// 若輸入出現(xiàn)異常,Scanner要丟棄上一次的輸入,否則 do-while會出現(xiàn)死循環(huán)
?? ??? ??? ??? ?s.next();
?? ??? ??? ?}
?
?? ??? ?} while (!inputIsOk);
?? ??? ?return inputNum;
?? ?}
?
}

效果圖:

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

相關(guān)文章

  • MyBatis主鍵自增的兩種實現(xiàn)方法

    MyBatis主鍵自增的兩種實現(xiàn)方法

    本文主要介紹了MyBatis主鍵自增的兩種實現(xiàn)方法,主要包括注解方式或配置文件方式來實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-01-01
  • java 出現(xiàn)問題javax.servlet.http.HttpServlet was not found解決方法

    java 出現(xiàn)問題javax.servlet.http.HttpServlet was not found解決方法

    這篇文章主要介紹了java 出現(xiàn)問題javax.servlet.http.HttpServlet was not found解決方法的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • Java swing框架實現(xiàn)的貪吃蛇游戲完整示例

    Java swing框架實現(xiàn)的貪吃蛇游戲完整示例

    這篇文章主要介紹了Java swing框架實現(xiàn)的貪吃蛇游戲,結(jié)合完整實例形式分析了java使用swing框架結(jié)合awt圖形繪制實現(xiàn)貪吃蛇游戲的具體步驟與相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2017-12-12
  • 一文教你如何判斷Java代碼中異步操作是否完成

    一文教你如何判斷Java代碼中異步操作是否完成

    在許多應(yīng)用程序中,我們經(jīng)常使用異步操作來提高性能和響應(yīng)度,這篇文章主要介紹了幾種常見的方法來判斷Java代碼中異步操作是否完成,希望對大家有所幫助
    2024-02-02
  • springboot通過SchedulingConfigurer實現(xiàn)多定時任務(wù)注冊及動態(tài)修改執(zhí)行周期(示例詳解)

    springboot通過SchedulingConfigurer實現(xiàn)多定時任務(wù)注冊及動態(tài)修改執(zhí)行周期(示例詳解)

    這篇文章主要介紹了springboot通過SchedulingConfigurer實現(xiàn)多定時任務(wù)注冊及動態(tài)修改執(zhí)行周期,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • Scala常用List列表操作方法示例

    Scala常用List列表操作方法示例

    這篇文章主要介紹了Scala常用List列表操作方法示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Java如何實現(xiàn)HTTP斷點續(xù)傳功能

    Java如何實現(xiàn)HTTP斷點續(xù)傳功能

    其實斷點續(xù)傳的原理很簡單,就是在Http的請求上和一般的下載有所不同而已,本文將詳細(xì)介紹Java如何實現(xiàn)HTTP斷點續(xù)傳功能,需要的朋友可以參考下
    2012-11-11
  • spring cloud config分布式配置中心的高可用問題

    spring cloud config分布式配置中心的高可用問題

    本文給大家介紹spring cloud config分布式配置中心的高可用問題,通過整合Eureka來實現(xiàn)配置中心的高可用,需要的朋友參考下本文
    2018-01-01
  • 深入了解Java行為型設(shè)計模式之策略模式

    深入了解Java行為型設(shè)計模式之策略模式

    策略模式屬于Java-設(shè)計模式中行為模式之一,該模式定義了一系列算法,并將每個算法封裝起來,使它們可以相互替換。本文將通過示例詳細(xì)講解這一模式,需要的可以參考一下
    2022-09-09
  • Java訪問權(quán)限原理與用法詳解

    Java訪問權(quán)限原理與用法詳解

    這篇文章主要介紹了Java訪問權(quán)限,結(jié)合實例形式詳細(xì)分析了java構(gòu)造者思想、包、訪問修飾符等相關(guān)原理、應(yīng)用與操作注意事項,需要的朋友可以參考下
    2020-02-02

最新評論

城市| 兰州市| 咸丰县| 军事| 明溪县| 马关县| 依安县| 海伦市| 乌拉特前旗| 余姚市| 滨州市| 钟祥市| 洪泽县| 农安县| 库伦旗| 集贤县| 会宁县| 彰化县| 靖州| 鲜城| 德格县| 开江县| 全椒县| 武义县| 邯郸县| 蒙山县| 通州市| 乐都县| 炎陵县| 凌海市| 临澧县| 西乌| 深圳市| 都兰县| 诏安县| 黔西县| 左云县| 枣阳市| 麟游县| 柘荣县| 定安县|