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

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
(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...
Data Structure in Java The following java method counts how many triples of integers in an...
Data Structure in Java The following java method counts how many triples of integers in an array of n distinct integers sum to zero. public static int count(int[] a) { int n = a.length; int count = 0; for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { for (int k = j+1; k < n; k++) { if (a[i] + a[j] + a[k] == 0) count++; } } }...
Please show solution and comments for this data structure using java.​ Implement a program in Java...
Please show solution and comments for this data structure using java.​ Implement a program in Java to convert an infix expression that includes (, ), +, -, *,     and / to postfix expression. For simplicity, your program will read from standard input (until the user enters the symbol “=”) an infix expression of single lower case and the operators +, -, /, *, and ( ), and output a postfix expression.
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...
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++
Using the Quality Summary and Call Center Data, provide a summary report for the vice president...
Using the Quality Summary and Call Center Data, provide a summary report for the vice president including the following information in an essay with a minimum of 500 words: List the relative frequency for overall type of calls, call quality, and call errors. Provide descriptive statistics for call time to include the mean, median, mode, variance, standard deviation, and range. Provide the following probabilities: CLM Error and AM Shift COV Error and PM Shift SAV Error or AM Shift Given...
Given below is simple random sample data for wait times, in minutes, for a call center....
Given below is simple random sample data for wait times, in minutes, for a call center. At the 98% confidence level, calculate the confidence interval estimate for the variance in wait time for the population of all calls at the call center. Assume the population is normally distributed. 12.1 11.5 13.4 16.2 11.3 12.2 11.3
Explain an Is-a relationship between classes in Java
Explain an Is-a relationship between classes in Java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT