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

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

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

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

實(shí)現(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;
?? ?}
?
?? ?// 對(duì)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;
?? ?}
?
?? ?// 按編號(hào)查找信息
?? ?public Person getPersonByNum(final int num) {
?? ??? ?if (num < 1) {
?? ??? ??? ?System.out.println("編號(hào)錯(cuò)誤");
?? ??? ??? ?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("編號(hào)\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("編號(hào)\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;
?? ?}
?? ?
?? ?//檢查對(duì)象是否存在
?? ?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);
?? ?}
?? ?
?? ?// 查找最大編號(hào)
?? ?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)運(yùn)行類
?? ?public static void main(String[] args) {
?? ??? ?SysRun sys = new SysRun();
?? ??? ?sys.sysRun();
?? ?}
?
?? ?public void sysRun() {
?? ??? ?System.out.println("啟動(dòng)系統(tǒng)管理系統(tǒng)");
?? ??? ?boolean isExit = false;
?? ??? ?do {
?? ??? ??? ?System.out.println("----------操作選項(xiàng)-------------");
?? ??? ??? ?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("----------操作選項(xiàng)-------------");
?? ??? ??? ?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("請(qǐng)輸入要?jiǎng)h除信息的編號(hào):");
?? ??? ?do {
?? ??? ??? ?num = getVaildInt();
?? ??? ??? ?isOk = is.CheckExitByNum(num);
?? ??? ??? ?if (isOk == true) {
?? ??? ??? ??? ?System.out.println("編號(hào)信息查找成功。");
?? ??? ??? ??? ?informationList.remove(is.getPersonByNum(num));
?? ??? ??? ?} else
?? ??? ??? ??? ?System.out.println("輸入編號(hào)有誤,請(qǐng)重新輸入:");
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// 修改Person
?? ?public void updatePerson() {
?? ??? ?System.out.println("請(qǐng)輸入要修改的信息編號(hào):");
?? ??? ?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("請(qǐng)輸入名字:");
?? ??? ??? ??? ?String name = s.next();
?? ??? ??? ??? ?System.out.println("請(qǐng)輸入性別:");
?? ??? ??? ??? ?String sex = getVaildSex();
?? ??? ??? ??? ?System.out.println("請(qǐng)輸入工資:");
?? ??? ??? ??? ?int salary = getVaildInt();
?
?? ??? ??? ??? ?p.setName(name);
?? ??? ??? ??? ?p.setSex(sex);
?? ??? ??? ??? ?p.setSalary(salary);
?? ??? ??? ??? ?is.showPerson();
?? ??? ??? ?} else
?? ??? ??? ??? ?System.out.println("輸入要修改的編號(hào)有誤,請(qǐng)重新輸入:");
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// 查看viewPerson()
?? ?private void viewPerson() {
?? ??? ?System.out.println("請(qǐng)輸入要查看的人的信息編號(hào):");
?? ??? ?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("無此編號(hào)的人的信息,請(qǐng)重新輸入:");
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?
?? ?}
?
?? ?// addPerson()
?? ?private void addPerson() {
?? ??? ?System.out.println("------------新增對(duì)象---------------");
?
?? ??? ?boolean isOk = false;
?? ??? ?String name = null;
?? ??? ?do {
?? ??? ??? ?System.out.println("請(qǐng)輸入名稱(且不能與現(xiàn)有的對(duì)象重名)");
?? ??? ??? ?name = s.next();
?? ??? ??? ?// 處理同名沖突
?? ??? ??? ?if (is.getPersonByName(name) == null) {
?? ??? ??? ??? ?isOk = true;
?? ??? ??? ?} else {
?? ??? ??? ??? ?System.out.println("該人信息已存在,請(qǐng)重新輸入!");
?? ??? ??? ??? ?s.next();
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?? ??? ?// other information
?? ??? ?System.out.println("請(qǐng)輸入其他信息...");
?? ??? ?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("輸入錯(cuò)誤,請(qǐng)重新輸入");
?? ??? ??? ??? ?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輸入讓 有誤,請(qǐng)重新輸入");
?? ??? ??? ?}
?? ??? ?} while (!isOk);
?? ??? ?return sex;
?? ?}
?
?? ?public int getCorrONum(String[] targetMenu) {
?? ??? ?System.out.println("請(qǐng)輸入要選擇的操作:");
?
?? ??? ?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("輸入錯(cuò)誤,請(qǐng)重新輸入!");
?? ??? ??? ??? ?}
?? ??? ??? ?} catch (InputMismatchException e) {
?? ??? ??? ??? ?System.out.println("輸入有誤,請(qǐng)重新輸入");
?? ??? ??? ??? ?// 若輸入出現(xiàn)異常,Scanner要丟棄上一次的輸入,否則 do-while會(huì)出現(xiàn)死循環(huán)
?? ??? ??? ??? ?s.next();
?? ??? ??? ?}
?
?? ??? ?} while (!inputIsOk);
?? ??? ?return inputNum;
?? ?}
?
}

效果圖:

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

相關(guān)文章

  • JPA之使用JPQL語句進(jìn)行增刪改查

    JPA之使用JPQL語句進(jìn)行增刪改查

    這篇文章主要介紹了JPA之使用JPQL語句進(jìn)行增刪改查,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-12-12
  • Java?8中的18個(gè)常用日期處理(收藏)

    Java?8中的18個(gè)常用日期處理(收藏)

    伴隨lambda表達(dá)式、streams以及一系列小優(yōu)化,Java 8 推出了全新的日期時(shí)間API,這篇文章主要介紹了Java?8的18個(gè)常用日期處理,需要的朋友可以參考下
    2022-04-04
  • Java的idea連接mongodb數(shù)據(jù)庫的詳細(xì)教程

    Java的idea連接mongodb數(shù)據(jù)庫的詳細(xì)教程

    這篇文章主要介紹了Java的idea連接mongodb數(shù)據(jù)庫的詳細(xì)教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 如何去掉IntelliJ IDEA中mybatis對(duì)應(yīng)的xml文件警告

    如何去掉IntelliJ IDEA中mybatis對(duì)應(yīng)的xml文件警告

    這篇文章主要介紹了如何去掉IntelliJ IDEA中mybatis對(duì)應(yīng)的xml文件警告問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-04-04
  • Java動(dòng)態(tài)代理實(shí)現(xiàn)方法小結(jié)

    Java動(dòng)態(tài)代理實(shí)現(xiàn)方法小結(jié)

    這篇文章主要介紹了Java動(dòng)態(tài)代理實(shí)現(xiàn)方法,結(jié)合實(shí)例形式總結(jié)分析了java基于JDK、CGLIB及CGLIB實(shí)現(xiàn)動(dòng)態(tài)代理的相關(guān)操作技巧,需要的朋友可以參考下
    2019-02-02
  • SpringBoot接口如何統(tǒng)一異常處理

    SpringBoot接口如何統(tǒng)一異常處理

    這篇文章主要介紹了SpringBoot接口如何統(tǒng)一異常處理,SpringBoot接口如何對(duì)異常進(jìn)行統(tǒng)一封裝,并統(tǒng)一返回呢?以下文的參數(shù)校驗(yàn)為例,如何優(yōu)雅的將參數(shù)校驗(yàn)的錯(cuò)誤信息統(tǒng)一處理并封裝返回呢,感興趣的下下伙伴可以一同參考一下
    2022-07-07
  • Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(59)

    Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(59)

    下面小編就為大家?guī)硪黄狫ava基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望可以幫到你
    2021-08-08
  • 詳解commons-pool2池化技術(shù)

    詳解commons-pool2池化技術(shù)

    本文主要是分析commons-pool2池化技術(shù)的實(shí)現(xiàn)方案,希望通過本文能讓讀者對(duì)commons-pool2的實(shí)現(xiàn)原理一個(gè)更全面的了解
    2021-06-06
  • Netty學(xué)習(xí)之理解selector原理示例

    Netty學(xué)習(xí)之理解selector原理示例

    這篇文章主要為大家介紹了Netty學(xué)習(xí)之理解selector原理示例使用分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪<BR>
    2023-07-07
  • Java讀取圖片EXIF信息的方法

    Java讀取圖片EXIF信息的方法

    這篇文章主要介紹了Java讀取圖片EXIF信息的方法,較為詳細(xì)的分析了圖片EXIF信息的概念、功能及java讀取EXIF信息的實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2015-07-07

最新評(píng)論