Question

In: Computer Science

in java. Design classes and data structure for a call center. Imagine that a call center...

in java. Design classes and data structure for a call center. Imagine that a call center has one fresher, one Technical Lead and one Manager. An incoming telephone call must be allocated to a fresher. If a fresher can’t handle the call, he or she must escalate the call to technical lead. If the TL is not free or not able to handle it, then the call should be escalated to Manager. If all three are busy , then put the user on hold. If they disconnect the call , delete them from the holding list.

Design the classes and data structures for this problem.

You should have a Menu class through which we can make a call, hang up and quit the program. If you wish you could add other options to it.

Solutions

Expert Solution

import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    System.out.println("Hello World");
    CallManager manager = new CallManager();

    manager.addRespondant(new Employee("R1", manager));
    manager.addRespondant(new Employee("R2", manager));
    manager.addRespondant(new Employee("R3", manager));

    manager.addManager(new Employee("M1", manager));
    manager.addManager(new Employee("M2", manager));
    manager.addManager(new Employee("M3", manager));

    manager.addDirector(new Employee("D1", manager));
    manager.addDirector(new Employee("D2", manager));

    Caller foo = new Caller("foo");

    manager.dispatch(foo); // should be R1
    manager.dispatch(new Call()); // should be R2
    manager.dispatch(new Call()); // should be R3
    manager.dispatch(new Call()); // should be M1
  }
}

class CallManager {
  List<List<Employee>> employeeLevels;
  List<List<Call>> waitQueue;

  CallManager() {
    this.employeeLevels = new ArrayList<>();
    this.employeeLevels.add(new ArrayList<>());
    this.employeeLevels.add(new ArrayList<>());
    this.employeeLevels.add(new ArrayList<>());
    this.waitQueue = new ArrayList<List<Call>>();
  }

  private Employee getCallHandler(Call call) {
    /* check all respondants */
    for (Employee respondant: employeeLevels.get(0)) {
      if (respondant.isFree()) return respondant;
    }

    /* check all managers */
    for (Employee manager: employeeLevels.get(1)) {
      if (manager.isFree()) return manager;
    }

    /* check all directors */
    for (Employee director: employeeLevels.get(2)) {
      if (director.isFree()) return director;
    }

    // No one is free
    return null; // returning null is not a good idea
  }

  public void addRespondant(Employee emp) {
    employeeLevels.get(0).add(emp);
  }

  public void addManager(Employee emp) {
    employeeLevels.get(1).add(emp);
  }

  public void addDirector(Employee emp) {
    employeeLevels.get(2).add(emp);
  }

  public void dispatch(Caller caller) {
    dispatch(new Call(caller));
  }

  public void dispatch(Call call) {
    /* check if any respondant is free */
    Employee handler = getCallHandler(call);
    if (handler == null) {
      System.out.println("Sorry, the line is busy, your call is going in wait queue");
      putCallInWaitQueue(call);
      return;
    }
    handler.assignCall(call);
    call.setEmployee(handler);
  }

  public void putCallInWaitQueue(Call call) {
    waitQueue.get(call.getRank()).add(call);
  }
}


class Employee {
  private String name;
  private Call currentCall;
  private CallManager callManager;

  Employee(String name, CallManager callManager) {
    this.name = name;
    this.callManager = callManager; // this is the required depedency hence must be there in constructor
  }

  public boolean isFree() {
    return this.currentCall == null;
  }

  private void escalateCall() {
    if (!isFree()) {
      currentCall.incrementRank();
      callManager.putCallInWaitQueue(currentCall);
    }
  }

  public void assignCall(Call call) {
    System.out.println(name + " Received call!");
    currentCall = call;
  }
}

final class Call { // final by default
  private int rank;
  private Caller caller;
  private Employee employee;

  Call() {
    this.rank = 0;
  }

  Call(Caller caller) {
    super();
    this.caller = caller;
  }

  public int getRank() {
    return rank;
  }

  public void incrementRank() {
    this.rank += 1;
  }

  public void setCaller(Caller caller) {
    this.caller = caller;
  }

  public void setEmployee(Employee employee) {
    this.employee = employee;
  }
}

final class Caller {
  private String name;

  Caller(String name) {
    this.name = name;
  }
}

Related Solutions

The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
The answer should be in JAVA. You will design and implement two classes to support a...
The answer should be in JAVA. You will design and implement two classes to support a client program, RockPaperScissorsGame.java, to simulate Rock-Paper-Scissors game. Read and understand the client program to find out the requirements for the HandShape and Player classes. The rules of the Rock-Paper-Scissors game are:     Scissors✌️ beats Paper✋ that beats Rock✊ that beats Scissors✌️ Additionally, to simplify the game logic (and complexify a little bit the HandSahpe class) , two players cannot show the same hand shape....
Develop a Java application to implement a binary tree data structure. A tree data structure starts...
Develop a Java application to implement a binary tree data structure. A tree data structure starts from the top node, called the root. Each node in the tree has a set of children, which are also nodes of the tree and can have children of their own, and so on. This keeps on going till we get to the bottom of the tree, to the “leaf” nodes. Each node in the tree, except for the root, has a parent. A...
(a) Imagine a straight line connecting the center of the moon with the center of the...
(a) Imagine a straight line connecting the center of the moon with the center of the earth. An object moving along this line would feel two main gravitational forces: A force pulling it towards the center of the earth, and a force pulling it towards the center of the moon. Find the distance along this line, measured from the center of the Moon, such that the net force is zero. (b). The moon-dwellers launch a rock from the surface of...
Problem-Solving Case: Training Call Center Employees The employees in a call center need to be able...
Problem-Solving Case: Training Call Center Employees The employees in a call center need to be able to speak to customers politely, but their skill set is more complicated than etiquette. They also need to handle a range of questions and problems about particular products. Whenever their company adds a new line of products or services, the employees have to be prepared to answer a new set of questions. Thus, training is an ongoing con- cern in call centers. The traditional...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class...
JAVA PROGRAM Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators,...
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects...
Q.We design classes to create objects in java. Write step wise procedure for (a).How these objects created in memory? (b). Which area of memory is used for creation of the objects? (c). What is difference between stack and heap memory in java?
Using a minimum of 2 classes create a java program that writes data to a file...
Using a minimum of 2 classes create a java program that writes data to a file when stopped and reads data from a file when started. The data should be in a readable format and the program should work in a way that stopping and starting is irrelevant (e.g. all data doesn't have to save just the important elements.) Program should be unique and semi-complex in some way.
In JAVA, Explain how classes properly handle data hiding and implementation hiding
In JAVA, Explain how classes properly handle data hiding and implementation hiding
Using classes and array data structure write methods with algorithms for a software that an airline...
Using classes and array data structure write methods with algorithms for a software that an airline can use to view available/booked seats, management booking, canceling booking and reorder seats. The solution should consist of a minimum of two classes with one class containing the main method and second class for managing a manipulating data. The choice of data structure for this assignment will be static one dimension arrays. in C++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT