用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函数中,先创建两个经理类和两个后勤类的员工对象,设置相应奖金和加班费后进行工作输出。

相关推荐

假设一个公司的员工分为志愿者Volunter和普通员工Employee,请先设计一个StuffMember的抽象类作为不同类型员工的父类,包含员工都具有的name,address以及phone属性(建议是public 或者是protected类型)。且:(1)需要建议以下格式的构造函数,并补充构造函数内的语句Public StuffMember(String ename, String eaddress,String iphone)(2)需要构造一个抽象方法:public abstract double pay();(3) 需要建立一个toString方法返回StuffMember的信息,请补充toString方法的方法体Public String toString(){}完成Volunter类,该类继承了StuffMember的抽象类并需要重载父类的pay()方法.(1) Volunter类中的pay方法返回一个浮点的0值就可以了。(2) 请显示定义Volunter类的带参数的构造函数。完成有薪资的Employee类,该类继承了StuffMember的抽象类,并含有自己的属性社会保险号String 类型的sccialSecurityNumber,和酬金率double 类型的payRate。(1)请建立5个参数的构造函数。(2) 请需要建立一个toString方法返回Employee的信息,请补充toString方法的方法体。(3) 建立Employee类的pay() 方法,该方法只返回员工的payRate*2500。建立Excutive类继承了Employee类,并包含一个double类型的奖金属性bonus。(1) 建立Excutive类的包含6个参数的构造函数(2) 重构pay()方法,需要实现工资计算Payment=super.pay() +bonus; Bonus=0;完成按小时付钱的员工类Hourly类,该类继承了Employee类,并包含一个double类型的奖金属性double hourWorked。(1) 建立Hourly类的包含6个参数的构造函数(2) 重构pay()方法,需要实现工资计算Payment=super.payRate * hourWorked; hourWorked=0;(3) 建立toStr

最新推荐

recommend-type

5153-微信小程序个人日程安排微信小程序的实现+ssm(源码+数据库+lun文).zip

本系统主要针对计算机相关专业的正在做毕业设计的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业。本系统主要针对计算机相关专业的正在做毕业设计的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业。本系统主要针对计算机相关专业的正在做毕业设计的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业。本系统主要针对计算机相关专业的正在做毕业设计的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业。
recommend-type

C++多态实现机制详解:虚函数与早期绑定

C++多态性实现机制是面向对象编程的重要特性,它允许在运行时根据对象的实际类型动态地调用相应的方法。本文主要关注于虚函数的使用,这是实现多态的关键技术之一。虚函数在基类中声明并被标记为virtual,当派生类重写该函数时,基类的指针或引用可以正确地调用派生类的版本。 在例1-1中,尽管定义了fish类,但基类animal中的breathe()方法并未被声明为虚函数。因此,当我们创建一个fish对象fh,并将其地址赋值给animal类型的指针pAn时,编译器在编译阶段就已经确定了函数的调用地址,这就是早期绑定。这意味着pAn指向的是animal类型的对象,所以调用的是animal类的breathe()函数,而不是fish类的版本,输出结果自然为"animalbreathe"。 要实现多态性,需要在基类中将至少一个成员函数声明为虚函数。这样,即使通过基类指针调用,也能根据实际对象的类型动态调用相应的重载版本。在C++中,使用关键字virtual来声明虚函数,如`virtual void breathe();`。如果在派生类中重写了这个函数,例如在fish类中定义`virtual void breathe() { cout << "fishbubble" << endl; }`,那么即使使用animal类型的指针,也能调用到fish类的breathe()方法。 内存模型的角度来看,当一个派生类对象被赋值给基类指针时,基类指针只存储了派生类对象的基类部分的地址。因此,即使进行类型转换,也只是访问基类的公共成员,而不会访问派生类特有的私有或保护成员。这就解释了为什么即使指针指向的是fish对象,调用的还是animal的breathe()函数。 总结来说,C++多态性是通过虚函数和早期/晚期绑定来实现的。理解这两个概念对于编写可扩展和灵活的代码至关重要。在设计程序时,合理使用多态能够提高代码的复用性和可维护性,使得程序结构更加模块化。通过虚函数,可以在不改变接口的情况下,让基类指针动态调用不同类型的子类对象上的同名方法,从而展现C++强大的继承和封装特性。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

Parallelization Techniques for Matlab Autocorrelation Function: Enhancing Efficiency in Big Data Analysis

# 1. Introduction to Matlab Autocorrelation Function The autocorrelation function is a vital analytical tool in time-domain signal processing, capable of measuring the similarity of a signal with itself at varying time lags. In Matlab, the autocorrelation function can be calculated using the `xcorr
recommend-type

matlab处理nc文件,nc文件是1979-2020年的全球降雨数据,获取一个省份区域内的日降雨量,代码怎么写

在MATLAB中处理`.nc`(NetCDF)文件通常需要使用`netcdf`函数库,它是一个用于读写多种科学数据格式的工具。对于全球降雨数据,你可以按照以下步骤编写代码: 1. 安装必要的库(如果还没有安装): ```matlab % 如果你尚未安装 netcdf 包,可以安装如下: if ~exist('netcdf', 'dir') disp('Installing the NetCDF toolbox...') addpath(genpath(fullfile(matlabroot,'toolbox','nco'))); end ``` 2. 加载nc文件并查看其结
recommend-type

Java多线程与异常处理详解

"Java多线程与进程调度是编程领域中的重要概念,尤其是在Java语言中。多线程允许程序同时执行多个任务,提高系统的效率和响应速度。Java通过Thread类和相关的同步原语支持多线程编程,而进程则是程序的一次执行实例,拥有独立的数据区域。线程作为进程内的执行单元,共享同一地址空间,减少了通信成本。多线程在单CPU系统中通过时间片轮转实现逻辑上的并发执行,而在多CPU系统中则能实现真正的并行。 在Java中,异常处理是保证程序健壮性的重要机制。异常是程序运行时发生的错误,通过捕获和处理异常,可以确保程序在遇到问题时能够优雅地恢复或终止,而不是崩溃。Java的异常处理机制使用try-catch-finally语句块来捕获和处理异常,提供了更高级的异常类型以及finally块确保关键代码的执行。 Jdb是Java的调试工具,特别适合调试多线程程序。它允许开发者设置断点,查看变量状态,单步执行代码,从而帮助定位和解决问题。在多线程环境中,理解线程的生命周期和状态(如新建、运行、阻塞、等待、结束)以及如何控制线程的执行顺序和同步是至关重要的。 Java的多线程支持包括Thread类和Runnable接口。通过继承Thread类或者实现Runnable接口,用户可以创建自己的线程。线程间同步是多线程编程中的一大挑战,Java提供了synchronized关键字、wait()、notify()和notifyAll()等方法来解决这个问题,防止数据竞争和死锁的发生。 在实际应用中,多线程常用于网络编程、数据库访问、GUI应用程序(如Swing或JavaFX)的事件处理、服务器端的并发处理等场景。例如,一个Web服务器可能需要同时处理多个客户端请求,这时使用多线程可以显著提升性能。此外,多线程在动画制作、游戏开发、多媒体应用等领域也发挥着重要作用,因为它允许同时处理渲染、计算和用户交互等多个任务。 Java的多线程与进程调度是构建高效、健壮应用的基础,而异常处理则提升了程序的稳定性。通过深入理解和熟练运用这些概念,开发者可以创建出更加灵活和可靠的软件系统。"
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

The Application of Autocorrelation Function in Economics: Economic Cycle Analysis and Forecasting Modeling

# Application of Autocorrelation Function in Economics: Analysis and Forecasting Models for Economic Cycles ## 1. Theoretical Foundations of Autocorrelation Function The Autocorrelation Function (ACF) is a statistical tool used to measure the correlation between data points in time series data tha
recommend-type

帮我用PHP写一个登录界面

当然可以,创建一个简单的PHP登录页面的基本步骤如下: ```php <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8"> <title>登录页面</title> </head> <body> <h2>用户登录</h2> <form method="post" action="login.php"> <label for="username">用户名:</label><br> <input type="text" id="username" name="us
recommend-type

校园导游系统:无向图实现最短路径探索

"校园导游系统是一个简单的程序设计实习项目,旨在用无向图表示校园的景点平面图,提供景点介绍和最短路径计算功能。该项目适用于学习数据结构和图算法,通过Floyd算法求解最短路径,并进行功能测试。" 这篇摘要提及的知识点包括: 1. **无向图**:在本系统中,无向图用于表示校园景点之间的关系,每个顶点代表一个景点,边表示景点之间的连接。无向图的特点是图中的边没有方向,任意两个顶点间可以互相到达。 2. **数据结构**:系统可能使用邻接矩阵来存储图数据,如`cost[n][n]`和`shortest[n][n]`分别表示边的权重和两点间的最短距离。`path[n][n]`则用于记录最短路径中经过的景点。 3. **景点介绍**:`introduce()`函数用于提供景点的相关信息,包括编号、名称和简介,这可能涉及到字符串处理和文件读取。 4. **最短路径算法**:通过`shortestdistance()`函数实现,可能是Dijkstra算法或Floyd-Warshall算法。这里特别提到了`floyed()`函数,这通常是Floyd算法的实现,用于计算所有顶点对之间的最短路径。 5. **Floyd-Warshall算法**:这是一种解决所有顶点对最短路径的动态规划算法。它通过迭代逐步更新每对顶点之间的最短路径,直到找到最终答案。 6. **函数说明**:`display(int i, int j)`用于输出从顶点i到顶点j的最短路径。这个函数可能需要解析`path[n][n]`数组,并将路径以用户可读的形式展示出来。 7. **测试用例**:系统进行了功能测试,包括景点介绍功能和最短路径计算功能的测试,以验证程序的正确性。测试用例包括输入和预期的输出,帮助识别程序的潜在问题。 8. **源代码**:源代码中包含了C语言的基本结构,如`#include`预处理器指令,`#define`定义常量,以及函数声明和定义。值得注意的是,`main()`函数是程序的入口点,而其他如`introduce()`, `shortestdistance()`, `floyed()`, 和 `display(int i, int j)` 是实现特定功能的子程序。 9. **全局变量**:`cost[n][n]`, `shortest[n][n]` 和 `path[n][n]`是全局变量,它们在整个程序范围内都可见,方便不同函数共享数据。 10. **C语言库**:`<stdio.h>`用于基本输入输出,`<process.h>`在这里可能用于进程控制,但请注意,在标准C库中并没有这个头文件,这可能是特定平台或编译器的扩展。 这个简单的校园导游系统是一个很好的教学案例,它涵盖了图论、数据结构、算法和软件测试等多个核心的计算机科学概念。对于学习者来说,通过实际操作这样的项目,可以加深对这些知识的理解和应用能力。