# 7.2. Call center

> Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can't handle the call, he or she must escalate the call to a manager. If the manager is not free or not able to handle it, then the call should be escalated to a director. Design the classes and data structures for this problem. Implement a method dispatchCall() which assigns a call to the first available employee.

Hints 363

There are 3 types of employees, and a number of them. 5 respondents why not, 1 manager and 1 director. In dispatch call, we check the respondents. If there's one free, they take it and they become busy. If all are busy, the manager is called. If the manager is busy, the director is called.

```java
public class CallCenter {
    private static int respondent;
    private static int manager;
    private static int director;
    protected CallCenter() {
        respondent = 5;
        manager = 1;
        director = 1;
    }
    protected dispatchCall() {
        if (respondent > 0) {
            respondent--;
        } else if (manager > 0) {
            manager--:
        }
        else if (director > 0) {
            director--;
        } else {
            return null;
        }
        return 1;
    }
}
```

## Solution

Make a class for each employee type. All employees have common traits like address, name, job title, age. These can be kept all in one class. There shold be a CallHandler class that routes the calls to the correct person.

[Solution codes](https://github.com/careercup/CtCI-6th-Edition/tree/master/Java/Ch%2007.%20Object-Oriented%20Design/Q7_02_Call_Center)