java员工管理系统,java编写用户管理系统
本文实例为大家分享了爪哇岛实现人员信息管理系统的具体代码,供大家参考,具体内容如下
实现增删改查.
爪哇岛入门的练手小程序
1.Person类
包P1;公共类人{ //人属性私有(同Internationalorganizations)国际组织数;私有字符串名称;私弦性;私人(同Internationalorganizations)国际组织薪金;公众人物(int num,String name,String sex,int salary){ super();this . num=numthis . name=name this . sex=sex this . salary=薪水;} //对佩罗松操作的方法public int getNum(){ return num;} public void setNum(int num){ this。num=num} public String getName(){ return name;} public void set name(String name){ this。name=名称;}公共字符串getSex(){ return sex;} public void setSex(字符串性){ this。性=性;} public int getSalary() { return薪金;} public void set salary(int salary){ this。工资=薪水;} }2.SysMenu类
包P1;公共类SysMenu { public static final String[]MENU={ 1 .员工信息管理, 2.退出 };公共静态最终字符串[] OPERATION_MENU={ 1 .新增, 2.查看, 3.修改, 4.删除, 5.返回 };public static void showMenu(String[]Menu){ for(int I=0;菜单长度系统。出去。print(菜单[I] t t );系统。出去。println();系统。出去。println(-);} }3.SysInfo类
包P1;导入Java。util。ArrayList导入Java。util。列表;public class SysInfo { private static List information List=new ArrayList();//获取信息列表公共静态列表getList(){返回信息列表;} }4.InformationService类
包P1;导入Java。util。列表;公共类信息服务{私人列表信息列表=sysinfo。getlist();//获取信息列表public List getList(){返回信息列表;} //按编号查找信息public Person get Person bynum(final int num){ if(num 1){ system。出去。println(编号错误);返回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("编号tt姓名tt性别tt薪水"); System.out.println(p.getNum()+ "tt" + p.getName() + "tt" + p.getSex() + "tt" + p.getSalary()); } //show all Person public void showPerson() { System.out.println("编号tt姓名tt性别tt薪水"); List ps = getList(); for (int i = 0; i < ps.size(); i++) { Person p = (Person) ps.get(i); System.out.println(p.getNum() + "tt" + p.getName() + "tt" + p.getSex() + "tt" + 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(); // 系统运行类 public static void main(String[] args) { SysRun sys = new SysRun(); sys.sysRun(); } public void sysRun() { System.out.println("启动系统管理系统"); boolean isExit = false; do { System.out.println("----------操作选项-------------"); SysMenu.showMenu(SysMenu.MENU); // 获取用户输入 int operNum = getCorrONum(SysMenu.MENU); // 管理操作 isExit = doManageNum(operNum); } while (!isExit); System.out.println("系统退出."); } 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("请输入名称(且不能与现有的对象重名)"); 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) { &am
郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。