Java implements employee management system and java employee management system

Source: Internet
Author: User
Tags class manager manager salary

Java implements employee management system and java employee management system

The examples in this article share the code for implementing the employee management system in Java for your reference. The specific content is as follows:

The main exercises in this system are as follows:

1. Process Control statements
2. Classes and objects
3. encapsulation, inheritance, and Polymorphism
4. Method overloading and rewriting
5. Access Modifier
6. static

Requirement Description:

Basic information about employees
--------- Ordinary employee ----------
Attributes: employee ID, employee name, employee title, number of days for leave, and basic salary
Ordinary employee salary:
Add 10% of work meals, 50% of post subsidies, and 200 yuan of housing subsidies on the basis of basic salary
Basic salary + basic salary * 0.1 + basic salary * 0.5 + 200
---------- Manager -----------
Attributes: employee ID, employee name, employee title, number of days for leave, and basic salary
Manager salary:
Add 20% of work meals, 50% of post subsidies, and 500 yuan of housing subsidies on the basis of basic salary
Basic salary + basic salary * 0.2 + basic salary * 0.5 + 500
----------- Directors -----------
Attributes: employee ID, employee name, employee title, number of days for leave, and basic salary
Directors' salary:
Add 8% of work meals, 30% of post subsidies, 2000 yuan of housing subsidies, and 3000 yuan of investment subsidies on the basis of basic salary
Basic salary + basic salary * 0.08 + basic salary * 0.3 + 2000 + 3000
----------- Others -----------
The deduction is the same for all employees.
No leave, full basic salary, leave, deduct average daily salary * days of leave

General design ideas:

Each employee has one parent class, one common employee, one manager, and one sub-class chairman. The salary method of the parent class is rewritten separately. The last test class.
Post-implementation Interface

There is no problem in writing the parent class subclass. Be sure to encapsulate it as much as possible. It is best to use private modification for attributes. Small series stole a lazy, mainly used time in the preparation of the test class o ( ̄ ε  ̄ *) o.
Note: because the system only saves the object in the object array and sets the array initialization time to 100, the system will automatically initialize each array element to null, therefore, when writing test methods, be sure to write a good judgment to prevent null pointer errors caused by traversal assignment. The small Editor is stupid, so it takes a while to write it out)
In addition, if you change the employee's information, pay attention to how to deal with changes in employee positions. After all, the object has changed and the method of dealing with wages is different.

The following code is provided:

The first is the parent class Employee.

// Parent class public class Employee {String ID; String name; String position; int holiday; double salary; public Employee () {} public void sumSalary () {} public void display () {System. out. println ("ID:" + ID + ", name:" + name + ", position:" + position + ", leave days:" + holiday + ", salary: "+ salary );}}

Three subclasses:

public class CommonEmployee extends Employee{ @Override public void sumSalary(){  super.salary=super.salary+super.salary*0.1+super.salary*0.5+200-super.holiday*(super.salary/30); }}public class Manager extends Employee{ @Override public void sumSalary(){  super.salary=super.salary+super.salary*0.2+super.salary*0.5+200-super.holiday*(super.salary/30); }}public class Director extends Employee{ @Override public void sumSalary(){  super.salary=super.salary+super.salary*0.08+super.salary*0.3+2000+3000-super.holiday*(super.salary/30); }}

The next step is the key test class. Here we have completed adding, deleting, modifying, and querying.

Public class TestEMD {static classes SC = new classes (System. in); static Employee [] em = new Employee [100]; public static void caoZuo () {System. out. println ("---- Wage Management System ----"); System. out. println ("-------------------------------"); System. out. println ("--- 1 add ---"); System. out. println ("--- 2 delete ---"); System. out. println ("--- 3 modify ---"); System. out. println ("--- 4 query ---"); System. out. println ("--- 0 exit --- "); System. out. println ("-------------------------------"); System. out. println ("Enter the operation you want to select:"); then SC = new then (System. in); String s = SC. next (); switch (s) {case "1": addEmployee (); break; case "2": delEmployee (); break; case "3": updateEmployee (); break; case "4": queryEmployee (); break; case "0": System. out. println ("Thank you for using O (∩ _ ∩) O"); break; default: System. out. println ("command error. Please enter it again! "); CaoZuo (); break;} public static void addEmployee () {System. out. println ("------ add employee ------"); System. out. println ("Enter the relevant information:"); System. out. print ("ID:"); String id = SC. next (); System. out. print ("name:"); String name = SC. next (); System. out. print ("title:"); String position = SC. next (); System. out. print ("days for leave:"); int holiday = SC. nextInt (); System. out. print ("basic salary:"); double salary = SC. nextDouble (); sw Itch (position) {case "regular Employee": Employee a = new CommonEmployee ();. ID = id;. name = name;. position = "ordinary employee";. holiday = holiday;. salary = salary;. sumSalary (); for (int I = 0; I <100; I ++) {if (em [I] = null) {em [I] = a; System. out. println ("added successfully! "); Em [I]. display (); break;} else {continue;} break; case "Manager": Employee B = new Manager (); B. ID = id; B. name = name; B. position = "manager"; B. holiday = holiday; B. salary = salary; B. sumSalary (); for (int I = 0; I <100; I ++) {if (em [I] = null) {em [I] = B; System. out. println ("added successfully! "); Em [I]. display (); break;} else {continue;} break; case "Chairman": Employee c = new Director (); c. ID = id; c. name = name; c. position = "Chairman of the Board"; c. holiday = holiday; c. salary = salary; c. sumSalary (); for (int I = 0; I <100; I ++) {if (em [I] = null) {em [I] = c; System. out. println ("added successfully! "); Em [I]. display (); break;} else {continue;} break; default: System. out. println (" this title does not exist. Please enter it again! "); AddEmployee (); break;} caoZuo ();} public static void delEmployee () {System. out. println ("---------- Delete employee ---------"); System. out. println ("Enter employee name:"); String n = SC. next (); for (int I = 0; I <100; I ++) {if (em [I]! = Null) {if (em [I]. name. equals (n) {System. out. println ("What you want to delete is:" + em [I]. toString (); System. out. println ("are you sure you want to delete it? \ N [Y] OK, [N] cancel "); String s = SC. next (); if (s. equals ("y") {em [I] = null; System. out. println ("deleted successfully! "); Try {Thread. sleep (2000);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace ();} caoZuo ();} else if (s. equals ("n") {caoZuo ();} else {System. out. println ("the input command is incorrect. Please enter it again! "); DelEmployee () ;}} else {if (I! = 99) {continue;} else {System. out. println ("the account you entered does not exist! Enter again! "); DelEmployee () ;}} else {if (I! = 99) {continue;} else {System. out. println ("the account you entered does not exist! Enter again! "); DelEmployee () ;}}} public static void updateEmployee () {System. out. println ("-------------- modify employee information -------------"); System. out. println ("Enter the name you want to modify:"); String s = SC. next (); out: for (int I = 0; I <100; I ++) {if (em [I]! = Null) {if (em [I]. name. equals (s) {System. out. println ("What You Want To modify is:"); em [I]. display (); System. out. println ("Please enter the relevant information again:"); System. out. print ("ID:"); String id = SC. next (); System. out. print ("name:"); String name = SC. next (); System. out. print ("title:"); String position = SC. next (); System. out. print ("days for leave:"); int holiday = SC. nextInt (); System. out. print ("basic salary:"); double salary = SC. nextDouble (); switch (positi On) {case "common employee": if (em [I]. position. equals ("regular employee") {em [I]. ID = id; em [I]. name = name; em [I]. position = position; em [I]. holiday = holiday; em [I]. salary = salary; em [I]. sumSalary (); System. out. println ("modified successfully! "); Em [I]. display ();} else {em [I] = null; Employee a = new CommonEmployee ();. ID = id;. name = name;. position = "ordinary employee";. holiday = holiday;. salary = salary;. sumSalary (); for (int j = 0; j <100; j ++) {if (em [j] = null) {em [j] = a; System. out. println ("modified successfully! "); Em [j]. display (); break;} else {continue ;}} break; case "manager": if (em [I]. position. equals ("manager") {em [I]. ID = id; em [I]. name = name; em [I]. position = position; em [I]. holiday = holiday; em [I]. salary = salary; em [I]. sumSalary (); System. out. println ("modified successfully! "); Em [I]. display ();} else {em [I] = null; Employee B = new Manager (); B. ID = id; B. name = name; B. position = "manager"; B. holiday = holiday; B. salary = salary; B. sumSalary (); for (int j = 0; j <100; j ++) {if (em [j] = null) {em [j] = B; System. out. println ("modified successfully! "); Em [j]. display (); break;} else {continue ;}} break; case "Chairman": if (em [I]. position. equals ("Chairman") {em [I]. ID = id; em [I]. name = name; em [I]. position = position; em [I]. holiday = holiday; em [I]. salary = salary; em [I]. sumSalary (); System. out. println ("modified successfully! "); Em [I]. display ();} else {em [I] = null; Employee c = new Director (); c. ID = id; c. name = name; c. position = "Chairman of the Board"; c. holiday = holiday; c. salary = salary; c. sumSalary (); for (int j = 0; j <100; j ++) {if (em [j] = null) {em [j] = c; System. out. println ("added successfully! "); Em [j]. display (); break;} else {continue ;}} break; default: System. out. println ("this title does not exist. Please enter it again! "); AddEmployee (); break;} try {Thread. sleep (2000);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace ();} caoZuo ();} else {if (I! = 99) {continue out;} else {System. out. println ("the employee you entered does not exist! Enter again! "); CaoZuo () ;}} else {if (I! = 99) {continue out;} else {System. out. println ("the employee you entered does not exist! Enter again! "); CaoZuo () ;}}} public static void queryEmployee () {System. out. println ("-------------- all employee information ---------------"); for (int I = 0; I <100; I ++) {if (em [I]! = Null) {em [I]. display () ;}try {Thread. sleep (2000);} catch (InterruptedException e) {// TODO Auto-generated catch block e. printStackTrace ();} caoZuo ();} public static void main (String [] args) {// TODO Auto-generated method stub TestEMD. caoZuo ();}}

After the program is written, I posted a post. I did not find any problems in the simple test. If you find anything wrong, please correct it. Thank you.

For more information, see management system development.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.