用java编写 private double monthlySalary; private double bonus; public ContractEmployee(int ID, String name, String gender, int age, double monthlySalary, double bonus) { super(ID, name, gender, age); this.monthlySalary = monthlySalary; this.bonus = bonus; } public void introduce() { System.out.println("我是正式员工" + super.name); } public void printSalary() { System.out.println("薪水为:" + (monthlySalary + bonus)); } }
时间: 2024-03-30 22:40:34 浏览: 97
这段代码是一个 Java 类的构造函数和两个方法的实现。这个类叫做 ContractEmployee,它继承自一个父类,父类的构造函数接收一个 ID、一个名字、一个性别和一个年龄。ContractEmployee 类有两个私有成员变量,一个是 monthlySalary,表示月工资,另一个是 bonus,表示奖金。构造函数接收这两个参数,并通过 super 调用父类的构造函数来初始化父类的成员变量。introduce 方法用于打印一条介绍信息,printSalary 方法用于打印该员工的薪水,即月工资加上奖金。
相关问题
使用java编写一个人事管理系统
好的,人事管理系统一般包括员工信息管理、薪资管理、考勤管理、招聘管理等模块。以下是一个简单的Java实现:
1. 员工信息管理模块:
```
public class Employee {
private String name;
private int age;
private String department;
private String position;
private double salary;
//构造函数
public Employee(String name, int age, String department, String position, double salary) {
this.name = name;
this.age = age;
this.department = department;
this.position = position;
this.salary = salary;
}
//getter和setter方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
}
```
2. 员工信息存储模块:
```
public class EmployeeDao {
private List<Employee> employees;
//构造函数
public EmployeeDao() {
this.employees = new ArrayList<>();
}
//添加员工
public void addEmployee(Employee employee) {
employees.add(employee);
}
//删除员工
public void deleteEmployee(Employee employee) {
employees.remove(employee);
}
//获取所有员工信息
public List<Employee> getAllEmployees() {
return employees;
}
//根据姓名查找员工信息
public List<Employee> getEmployeesByName(String name) {
List<Employee> result = new ArrayList<>();
for (Employee e : employees) {
if (e.getName().equals(name)) {
result.add(e);
}
}
return result;
}
//根据部门查找员工信息
public List<Employee> getEmployeesByDepartment(String department) {
List<Employee> result = new ArrayList<>();
for (Employee e : employees) {
if (e.getDepartment().equals(department)) {
result.add(e);
}
}
return result;
}
//根据职位查找员工信息
public List<Employee> getEmployeesByPosition(String position) {
List<Employee> result = new ArrayList<>();
for (Employee e : employees) {
if (e.getPosition().equals(position)) {
result.add(e);
}
}
return result;
}
}
```
3. 薪资管理模块:
```
public class Salary {
private Employee employee;
private double basicSalary;
private double bonus;
private double deduct;
private double totalSalary;
//构造函数
public Salary(Employee employee, double basicSalary, double bonus, double deduct) {
this.employee = employee;
this.basicSalary = basicSalary;
this.bonus = bonus;
this.deduct = deduct;
this.totalSalary = basicSalary + bonus - deduct;
}
//getter和setter方法
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public double getBasicSalary() {
return basicSalary;
}
public void setBasicSalary(double basicSalary) {
this.basicSalary = basicSalary;
}
public double getBonus() {
return bonus;
}
public void setBonus(double bonus) {
this.bonus = bonus;
}
public double getDeduct() {
return deduct;
}
public void setDeduct(double deduct) {
this.deduct = deduct;
}
public double getTotalSalary() {
return totalSalary;
}
public void setTotalSalary(double totalSalary) {
this.totalSalary = totalSalary;
}
}
```
4. 薪资管理存储模块:
```
public class SalaryDao {
private List<Salary> salaries;
//构造函数
public SalaryDao() {
this.salaries = new ArrayList<>();
}
//添加薪资记录
public void addSalary(Salary salary) {
salaries.add(salary);
}
//删除薪资记录
public void deleteSalary(Salary salary) {
salaries.remove(salary);
}
//获取所有薪资记录
public List<Salary> getAllSalaries() {
return salaries;
}
//根据员工姓名查找薪资记录
public List<Salary> getSalariesByEmployeeName(String name) {
List<Salary> result = new ArrayList<>();
for (Salary s : salaries) {
if (s.getEmployee().getName().equals(name)) {
result.add(s);
}
}
return result;
}
}
```
5. 考勤管理模块:
```
public class Attendance {
private Employee employee;
private Date date;
private boolean isPresent;
//构造函数
public Attendance(Employee employee, Date date, boolean isPresent) {
this.employee = employee;
this.date = date;
this.isPresent = isPresent;
}
//getter和setter方法
public Employee getEmployee() {
return employee;
}
public void setEmployee(Employee employee) {
this.employee = employee;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public boolean isPresent() {
return isPresent;
}
public void setPresent(boolean isPresent) {
this.isPresent = isPresent;
}
}
```
6. 考勤管理存储模块:
```
public class AttendanceDao {
private List<Attendance> attendances;
//构造函数
public AttendanceDao() {
this.attendances = new ArrayList<>();
}
//添加考勤记录
public void addAttendance(Attendance attendance) {
attendances.add(attendance);
}
//删除考勤记录
public void deleteAttendance(Attendance attendance) {
attendances.remove(attendance);
}
//获取所有考勤记录
public List<Attendance> getAllAttendances() {
return attendances;
}
//根据员工姓名查找考勤记录
public List<Attendance> getAttendancesByEmployeeName(String name) {
List<Attendance> result = new ArrayList<>();
for (Attendance a : attendances) {
if (a.getEmployee().getName().equals(name)) {
result.add(a);
}
}
return result;
}
}
```
7. 招聘管理模块:
```
public class Recruitment {
private String position;
private int numberOfPositions;
private String requirement;
//构造函数
public Recruitment(String position, int numberOfPositions, String requirement) {
this.position = position;
this.numberOfPositions = numberOfPositions;
this.requirement = requirement;
}
//getter和setter方法
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
public int getNumberOfPositions() {
return numberOfPositions;
}
public void setNumberOfPositions(int numberOfPositions) {
this.numberOfPositions = numberOfPositions;
}
public String getRequirement() {
return requirement;
}
public void setRequirement(String requirement) {
this.requirement = requirement;
}
}
```
8. 招聘管理存储模块:
```
public class RecruitmentDao {
private List<Recruitment> recruitments;
//构造函数
public RecruitmentDao() {
this.recruitments = new ArrayList<>();
}
//添加招聘信息
public void addRecruitment(Recruitment recruitment) {
recruitments.add(recruitment);
}
//删除招聘信息
public void deleteRecruitment(Recruitment recruitment) {
recruitments.remove(recruitment);
}
//获取所有招聘信息
public List<Recruitment> getAllRecruitments() {
return recruitments;
}
//根据职位查找招聘信息
public List<Recruitment> getRecruitmentsByPosition(String position) {
List<Recruitment> result = new ArrayList<>();
for (Recruitment r : recruitments) {
if (r.getPosition().equals(position)) {
result.add(r);
}
}
return result;
}
}
```
以上就是一个简单的Java实现的人事管理系统,其中包括员工信息管理、薪资管理、考勤管理、招聘管理等模块。当然,这只是一个简单的实现,实际应用中还需要考虑更多的因素,例如安全性、性能等。
运行这个代码public class Test_03 { public static void main(String[] args) { //员工类:工号\职位\姓名\工资 //经理级:奖金 (奖金和加班费分别用set和get是因为输错,所以单独输入) //后勤:加班费 Manager s1 = new Manager("0001","总经理","张华",5000); s1.setBonus(500);//经理级奖金 s1.work(); Manager s2 = new Manager("0002","副经理","李小",4500); s2.setBonus(350);//经理级奖金 s2.work(); GeneralStaff s3 =new GeneralStaff("1000","后勤主管","叶斯",3300); s3.setOverTimePay(1000);//加班费 s3.work(); GeneralStaff s4 =new GeneralStaff("1001","后勤员工","雷五",2800); s4.setOverTimePay(1000);//加班费 s4.work(); } } class Manager extends Staff {//经理级 public Manager(String id, String position, String name, double salary) { super(id, position, name, salary); } private double bonus;// 奖金 public void setBonus(double bonus) { this.bonus = bonus; } public void work() { super.work(); System.out.println(";奖金:"+ bonus); } } class GeneralStaff extends Staff {// 普通员工类 public GeneralStaff(String id, String position, String name, double salary) { super(id, position, name, salary); // TODO Auto-generated constructor stub } private double overtimepay;// 加班费 public void setOverTimePay(double overtimepay) { this.overtimepay = overtimepay; } public void work() { super.work(); System.out.println(";加班费:"+overtimepay); } } class Staff {// 员工类 private String id;// 工号 private String position;// 职位 private String name;// 姓名 private double salary;// 工资 public Staff(String id, String position, String name, double salary) { super(); this.id = id; this.position = position; this.name = name; this.salary = salary; } public void work() { System.out.print("工号:" + id + ";职位:" + position + ";姓名:" + name + ";工资:" + salary); } }
这段代码是一个员工工资管理系统的实现,包括经理和普通员工两种角色。对于经理级别的员工,还有奖金的设置和输出;对于后勤类的员工,还有加班费的设置和输出。在main函数中,先创建两个经理类和两个后勤类的员工对象,设置相应奖金和加班费后进行工作输出。