Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Java to realize Enterprise employee Management system

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

In this article, the editor introduces in detail "how to use Java to achieve enterprise employee management system", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use Java to achieve enterprise employee management system" can help you solve your doubts.

First, you create an employee class

Define the attributes that an employee should have: job number, name, gender, position, age, salary, department

/ * * employee attribute * / private int sno;// work number private String name;// name private String sex;// gender private String job;// position private int age;// Age private int money;// salary private String section;// Department

Fast Generation with eclipse Shortcut Alt+s/ and its attribute get/set method and Constructor Constructor

Public Emp (int sno, String name, String sex, String job, int age, int money, String section) {this.sno = sno; this.name = name; this.sex = sex; this.job = job; this.age = age; this.money=money; this.section = section;} public int getSno () {return sno } public void setSno (int sno) {this.sno = sno;} 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 String getJob () {return job } public void setJob (String job) {this.job = job;} public int getAge () {return age;} public void setAge (int age) {this.age = age;} public int getMoney () {return money;} public void setMoney (int money) {this.money = money;} public String getSection () {return section } public void setSection (String section) {this.section = section;}

This makes it easy to complete the basic properties of an employee class.

Then complete the method to implement the employee properties in the newly created class

The output of employee information is realized through constructors and methods, and each attribute of the employee is completed by multiple methods.

I define an array of specified length here, and then expand its capacity in a way.

Emp [] list = new Emp [10]; / * * initialize the index of the array * / public int index = 0; public void add (Emp s) {list [index++] = s;}

Through the method, you can output the attributes of employees.

/ * * output of employee information * / public void listStu () {System.out.println ("Citizen Information:" + "\ t" + "Job ID" + "\ t" + "name" + "\ t" + "gender" + "position" + "Age" + "Age" + "salary" + "\ t" + "Department") For (Emp s: list) {if (s! = null) {System.out.println ("\ t" + s.getSno () + "\ t" + s.getName () + "\ t" + s.getSex () + "\ t" + s.getJob () + "\ t" + s.getAge () + "\ t" + s.getMoney () + "\ t" + s.getSection () }} System.out.println ();}

To query, modify and delete employees through the job number.

/ * * query employee information according to work number * / public Emp findBySno (int sno) {for (Emp s: list) {if (s! = null & & s.getSno () = = sno) {System.out.println (s.getName () + "/" + s.getSex () + "/" + s.getJob () + "/" + s.getMoney () + "/" + s.getSection () System.out.println (); return s;}} return null;} / * * change salary according to job number * / public void updata (int sno, int money) {/ / 1. Query the employee Emp s = this.findBySno (sno); if (s! = null) {s.setMoney (money); System.out.println ("you change the employee information as follows:") System.out.println (s.getName () + "/" + s.getSex () + "/" + s.getJob () + "/" + s.getMoney () + "/" + s.getSection ()) }} / * * remove the specified location element in the array * / public Emp remove (int sno) {/ / get the element for (int I = 0; I < list.length; iTunes +) {Emp emp = list [I]; if (emp! = null & & emp.getSno () = = sno) {sno = I / / find the corresponding position of sno in the array and assign this address number to sno}} / * * use the found sno corresponding position to find * / Emp s = list [sno]; / / at this time, sno (work number) has been replaced with the position in the corresponding array / / set the element of the target location to 0 list [sno] = null System.arraycopy (list, sno, list, sno + 1, list.length-(sno + 1)); / / Index decreases accordingly index--; / / elements to be deleted are returned to listStu (); return s;}

These are the codes that modify and judge the conditions of employee information.

Finally, create a class to output the above information

This class calls the methods of other classes through objects.

/ / Job number, name, age, salary department / / sno name sex job age money sectionEmp S1 = new Emp (101,101," Tryci "," male "," department manager ", 23, 8888," Java "); Emp S2 = new Emp (102,102," Zhang San "," male "," project manager ", 21, 7777," C++ ") Emp S3 = new Emp, "Li Si", "male", "department manager", 25, 6666, "front end"); Emp S4 = new Emp (104,104, "Wang Wu", "male", "project manager", 24, 5555, "Java"); Emp S5 = new Emp (105, "Zhao Liu", "male", "cleaning staff", 22, 4444, "hygiene"); Principal sm = new Principal (); sm.add (S1) Sm.add (S2); sm.add (S3); sm.add (S4); sm.add (S5); sm.listStu (); / / query employee information according to the job number? System.out.print ("you query employee information:"); sm.findBySno (101l); / / change the salary of the student with student number 104to sm.updata (104,102); / / delete an element in the array, sm.remove (6666)

Although a basic employee information management system is completed in this way, the contents and methods are very low in technical content, and the information can not be entered and modified through operations such as the console.

Read here, this article "how to use Java to achieve enterprise employee management system" article has been introduced, want to master the knowledge of this article still need to practice and use in order to understand, if you want to know more related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report