用java写出酒店里面有厨师,服务员,经理等员工,员工都有姓名,员工编号等信息,酒店规定员工上班必须打卡、工作,且厨师和服务员必须提供vip服务(如:厨师vip服务加菜服务员vip服务嘘寒问暖)分析以上描述,使用面向对象的知识,设计酒店中的各类员工
时间: 2024-11-18 14:19:01 浏览: 5
连锁酒店员工绩效考核办法
为了实现这个需求,我们可以使用面向对象的设计方法来创建几个相关的类:Employee(员工)、Cook(厨师)、Waiter(服务员)以及Manager(经理)。每个类都会有共同的基本属性如name(姓名)和employeeID(员工编号),并且继承自一个抽象基类Employee。同时,我们会添加一些特殊的方法来模拟打卡、工作和VIP服务。
首先,定义一个Employee类作为基类:
```java
public abstract class Employee {
private String name;
private int employeeID;
public Employee(String name, int employeeID) {
this.name = name;
this.employeeID = employeeID;
}
// 公共方法
public void clockIn() {
System.out.println(name + " has clocked in.");
}
public void clockOut() {
System.out.println(name + " has clocked out.");
}
// 获取姓名和员工编号
public String getName() {
return name;
}
public int getEmployeeID() {
return employeeID;
}
}
```
然后为厨师、服务员和经理分别创建子类,继承自Employee,并添加特定的功能:
```java
public class Cook extends Employee {
public Cook(String name, int employeeID) {
super(name, employeeID);
}
@Override
public void provideVipService() {
System.out.println(name + " is providing an extra dish for a VIP customer.");
}
}
public class Waiter extends Employee {
public Waiter(String name, int employeeID) {
super(name, employeeID);
}
@Override
public void provideVipService() {
System.out.println(name + " is showing extra care and attention to a VIP guest.");
}
}
public class Manager extends Employee {
public Manager(String name, int employeeID) {
super(name, employeeID);
}
// 管理者可能不直接提供VIP服务
@Override
public void provideVipService() {
System.out.println(name + " is overseeing the VIP service.");
}
}
```
现在你可以根据这些类创建具体的员工实例并调用相应的方法:
```java
public static void main(String[] args) {
Cook cook = new Cook("John Doe", 1001);
Waiter waiter = new Waiter("Jane Smith", 1002);
Manager manager = new Manager("Alice Johnson", 1003);
cook.clockIn();
cook.provideVipService();
waiter.clockIn();
waiter.provideVipService();
manager.clockIn();
manager.provideVipService();
}
```
阅读全文