Chapter Twelve Cases Hotel Cases

Case introduction:

A five-star hotel with strong capital needs to recruit many employees (managers, chefs, waiters). Recruited employees need to record personal information (name, job number, manager-specific bonus attributes). They all have their own work to do.

This case needs to fulfill the following requirements:

  Get lucky hotel employees;

  The hotel offers VIP service, and the hotel's chefs and waiters can provide VIP service. (The chef increases the amount of dishes, and the waiter pours wine for the customer).

  Write the test class:

    Add multiple employees to the hotel (including 1 manager, 1 cook, and 2 waiters);

    Invoke job function for hotel staff

    Invoke the VIP service function of hotel staff


Implementation code:

/*
 * Hotel's VIP service
 * Chef and waiter
 */

public interface VIP {
public abstract void services();
}

/*
 * Hotel's employee class
 * Employee commonality, name, job number work method
 */

public abstract class Employee {
private String name;
private String id; public Employee(){} public Employee(String name,String id){ this.name = name; this.id = id; } public abstract void work(); public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; }



















public void setId(String id) {
this.id = id;
}
}

/*
 * Define the lucky employee class
 * Create a Start type collection
 * Use Random to obtain random numbers
 */

import java.util.Random;

public class Randomname {
String[] name = {"Cuihua","Sauerkraut","Laoganma","Laoganda","Xiaoname"};
public void Randoms() {
Random r = new Random();
int index = r.nextInt (name.length);
System.out.println("======Lucky Employee=====");
System.out.println(name[index]);
}
}

/*
 * Define Chef Class
 * Belongs to One type of employee, with additional service functions
 * Inherit Employee, implement VIP interface
 */

public class ChuShi extends Employee implements VIP{
//Empty parameter constructor
public ChuShi(){} //There are parameter constructors public ChuShi(String name,String id){ super(name,id); } //Abstract method overrides public void work(){ System.out.println("Chef In cooking"); } public void services(){ System.out.println("The chef increases the amount of cooking"); } } /*  * Define the waiter class  * It belongs to the employee type, with additional service functions  * Inherit Employee, implement VIP interface  */ public class FuWuYuan extends Employee implements VIP{ //Empty parameter constructor public FuWuYuan() { super(); }    //Full parameter constructor public FuWuYuan(String name, String id) { super(name, id) ; } //Abstract method override

































public void work(){
System.out.println("The waiter is serving the food");
} public void services(){ System.out.println("The waiter pours wine for the customer"); } } /*  * Define the manager class  * Belongs to one type of employee, no VIP function  * Own bonus attribute  */ public class JingLi extends Employee { //Empty parameter constructor public JingLi(){} //Full parameter constructor public JingLi(String name,String id,double money){ super(name, id); this.money = money; } //define bonus property private double money; public double getMoney() { return money; } public void setMoney(double money) { this.money = money; }
































//Override the abstract method
public void work(){
System.out.println("Management, I will punish anyone who makes a mistake");
}
}

public class Test {
public static void main(String[] args) {
//Create 1 1 manager, 2 waiters, 2 chefs
JingLi jl = new JingLi("Xiaoname", "Board 001", 123456789.32);
jl.work(); FuWuYuan f1 = new FuWuYuan("Cuihua", "Service Department 001" "); FuWuYuan f2 = new FuWuYuan("Sauerkraut", "Service Department 002"); f1.work(); f1.services(); f2.work(); f2.services(); ChuShi c1 = new ChuShi( "Lao Ganma", "Hou Kitchen 001"); ChuShi c2 = new ChuShi("Lao Gan Daddy", "Hou Kitchen 002"); c1.work(); c1.services(); c2.work(); c2. services(); new Randomname().Randoms(); }





















}

operation result:


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325195044&siteId=291194637