java题目
在某公司中,雇员有两个类别:普通雇员和经理。现设计人力资源管理系统,其中,普通雇员有姓名、出生年份、雇佣日期、岗位、薪水等属性,有打卡、上班、下班等方法。而经理除了具有普...
在某公司中,雇员有两个类别:普通雇员和经理。现设计人力资源管理系统,其中,普通雇员有姓名、出生年份、雇佣日期、岗位、薪水等属性,有打卡、上班、下班等方法。而经理除了具有普通雇员所有的属性和方法之外,还具有岗位级别属性、具有跟下属谈话、招聘新雇员、辞退雇员等方法。
请设计雇员类和经理类,并通过建立雇员和经理的对象,调用雇员与经理类的方法,实现雇员打卡上班,下班等功能,经理谈话、招聘新雇员、辞退雇员等功能。
注意:谈话、招聘、辞退等功能需接收雇员对象作为参数,并描述了和谁谈话,招聘谁和辞退谁。 展开
请设计雇员类和经理类,并通过建立雇员和经理的对象,调用雇员与经理类的方法,实现雇员打卡上班,下班等功能,经理谈话、招聘新雇员、辞退雇员等功能。
注意:谈话、招聘、辞退等功能需接收雇员对象作为参数,并描述了和谁谈话,招聘谁和辞退谁。 展开
2个回答
展开全部
以下是Java中实现题目要求的雇员类(Employee)和经理类(Manager)的代码:
```java
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class Employee {
private String name;
private int birthYear;
private LocalDate hireDate;
private String position;
private double salary;
public Employee(String name, int birthYear, String position, double salary) {
this.name = name;
this.birthYear = birthYear;
this.hireDate = LocalDate.now();
this.position = position;
this.salary = salary;
}
// 打卡上班
public void clockIn() {
System.out.println(name + " 上班打卡");
}
// 下班
public void clockOut() {
System.out.println(name + " 下班打卡");
}
// 上班
public void work() {
System.out.println(name + " 开始工作");
}
public String getName() {
return name;
}
public int getBirthYear() {
return birthYear;
}
public LocalDate getHireDate() {
return hireDate;
}
public String getPosition() {
return position;
}
public double getSalary() {
return salary;
}
}
class Manager extends Employee {
private String level;
private List<Employee> subordinates;
public Manager(String name, int birthYear, String position, double salary, String level) {
super(name, birthYear, position, salary);
this.level = level;
this.subordinates = new ArrayList<>();
}
// 跟下属谈话
public void talkTo(Employee employee) {
System.out.println(getName() + " 在和 " + employee.getName() + " 谈话");
}
// 招聘新雇员
public void hire(Employee employee) {
subordinates.add(employee);
System.out.println(getName() + " 招聘了新员工 " + employee.getName());
}
// 辞退雇员
public void fire(Employee employee) {
subordinates.remove(employee);
System.out.println(getName() + " 辞退了员工 " + employee.getName());
}
public String getLevel() {
return level;
}
public List<Employee> getSubordinates() {
return subordinates;
}
}
```
在以上代码中,Employee类表示普通雇员,包含姓名、出生年份、雇佣日期、岗位、薪水等属性,以及打卡、上班、下班等方法。Manager类继承自Employee类,并增加了岗位级别属性、subordinates属性表示下属列表,以及跟下属谈话、招聘新雇员、辞退雇员等方法。
可以编写一个测试类来测试以上两个类的功能,例如:
```java
public class EmployeeManagementSystem {
public static void main(String[] args) {
Employee alice = new Employee("Alice", 1990, "Software Engineer", 8000);
Employee bob = new Employee("Bob", 1985, "Senior Software Engineer", 12000);
Manager charlie = new Manager("Charlie", 1980, "Engineering Manager", 20000, "Director");
alice.clockIn();
bob.clockIn();
alice.work();
bob.work();
alice.clockOut();
bob.clockOut();
charlie.talkTo(alice);
charlie.talkTo(bob);
charlie.hire(new Employee("David", 1995, "Software Engineer", 7000));
charlie.hire(new Employee("Emily", 1992, "Software Engineer", 8500));
System.out.println(charlie.getName() + " 的下属有:");
for (Employee employee : charlie.getSubordinates()) {
System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary());
}
charlie.fire(alice);
System.out.println(charlie.getName() + " 的下属有:");
for (Employee employee : charlie.getSubordinates()) {
System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary());
}
}
}
```
在以上代码中,首先创建了三个雇员对象,分别是 Alice、Bob 和 Charlie。然后调用它们的打卡、上
```java
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
public class Employee {
private String name;
private int birthYear;
private LocalDate hireDate;
private String position;
private double salary;
public Employee(String name, int birthYear, String position, double salary) {
this.name = name;
this.birthYear = birthYear;
this.hireDate = LocalDate.now();
this.position = position;
this.salary = salary;
}
// 打卡上班
public void clockIn() {
System.out.println(name + " 上班打卡");
}
// 下班
public void clockOut() {
System.out.println(name + " 下班打卡");
}
// 上班
public void work() {
System.out.println(name + " 开始工作");
}
public String getName() {
return name;
}
public int getBirthYear() {
return birthYear;
}
public LocalDate getHireDate() {
return hireDate;
}
public String getPosition() {
return position;
}
public double getSalary() {
return salary;
}
}
class Manager extends Employee {
private String level;
private List<Employee> subordinates;
public Manager(String name, int birthYear, String position, double salary, String level) {
super(name, birthYear, position, salary);
this.level = level;
this.subordinates = new ArrayList<>();
}
// 跟下属谈话
public void talkTo(Employee employee) {
System.out.println(getName() + " 在和 " + employee.getName() + " 谈话");
}
// 招聘新雇员
public void hire(Employee employee) {
subordinates.add(employee);
System.out.println(getName() + " 招聘了新员工 " + employee.getName());
}
// 辞退雇员
public void fire(Employee employee) {
subordinates.remove(employee);
System.out.println(getName() + " 辞退了员工 " + employee.getName());
}
public String getLevel() {
return level;
}
public List<Employee> getSubordinates() {
return subordinates;
}
}
```
在以上代码中,Employee类表示普通雇员,包含姓名、出生年份、雇佣日期、岗位、薪水等属性,以及打卡、上班、下班等方法。Manager类继承自Employee类,并增加了岗位级别属性、subordinates属性表示下属列表,以及跟下属谈话、招聘新雇员、辞退雇员等方法。
可以编写一个测试类来测试以上两个类的功能,例如:
```java
public class EmployeeManagementSystem {
public static void main(String[] args) {
Employee alice = new Employee("Alice", 1990, "Software Engineer", 8000);
Employee bob = new Employee("Bob", 1985, "Senior Software Engineer", 12000);
Manager charlie = new Manager("Charlie", 1980, "Engineering Manager", 20000, "Director");
alice.clockIn();
bob.clockIn();
alice.work();
bob.work();
alice.clockOut();
bob.clockOut();
charlie.talkTo(alice);
charlie.talkTo(bob);
charlie.hire(new Employee("David", 1995, "Software Engineer", 7000));
charlie.hire(new Employee("Emily", 1992, "Software Engineer", 8500));
System.out.println(charlie.getName() + " 的下属有:");
for (Employee employee : charlie.getSubordinates()) {
System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary());
}
charlie.fire(alice);
System.out.println(charlie.getName() + " 的下属有:");
for (Employee employee : charlie.getSubordinates()) {
System.out.println(employee.getName() + "," + employee.getPosition() + "," + employee.getSalary());
}
}
}
```
在以上代码中,首先创建了三个雇员对象,分别是 Alice、Bob 和 Charlie。然后调用它们的打卡、上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |