Java Java Data Structures Efficiency! Call Center Queue

Enyang Mercy
PRO
Enyang Mercy
Pro Student 2,339 Points

Custom Serialization While loop Call center

Help with the right codes 3 assignments to do

CallCenter.java
import java.util.ArrayDeque;
import java.util.Queue;

public class CallCenter {
  Queue<CustomerSupportRep> mSupportReps;

  public CallCenter(Queue<CustomerSupportRep> queue) {
    mSupportReps = queue;
  }

  public void acceptCustomer(Customer customer) {
    CustomerSupportRep csr;
     while (( line = reader.readLine() != null) {
       String[] args = line.split("\\ |");
       playSong(new Song(args[0]));
     }

     public void CustomerSupportRep(String name) {
     CustomerSupportRep.getAssistedCustomer();


  }

    /********************************************
     * TODO (1) 
     * Wait until there is an available rep in the queue.
     * While there is not one available, playHoldMusic
     * HINT: That while assignmentcheck loop syntax we used to 
      *      read files seems pretty similar
     ********************************************
     */

    /********************************************
     * TODO (2) 
     * After we have assigned the rep, call the 
     * assist method and pass in the customer
     ********************************************
     */

    /********************************************
     * TODO (3) 
     * Since the customer support rep is done with
     * assisting, put them back into the queue.
     ********************************************
     */

  } 

  public void playHoldMusic() {
    System.out.println("Smooooooth Operator.....");
  }

}
CustomerSupportRep.java
import java.util.List;
import java.util.ArrayList;

public class CustomerSupportRep {
  private String mName;
  private List<Customer> mAssistedCustomers;

  public CustomerSupportRep(String name) {
    mName = name;
    mAssistedCustomers = new ArrayList<Customer>();
  }

  public void assist(Customer customer) {
    System.out.printf("Hello %s, my name is %s, how can I assist you.%n",
                      customer.getName(),
                      mName);
    System.out.println("...");
    System.out.println("Is there anything else I can help you with?");
    mAssistedCustomers.add(customer);
  }

  public List<Customer> getAssistedCustomers() {
    return mAssistedCustomers;
  }

}
Customer.java
public class Customer {
  private String mName;

  public Customer(String name) {
    mName = name;
  }

  public String getName() {
    return mName;
  }

}

2 Answers

Yanuar Prakoso
Yanuar Prakoso
15,076 Points

Hi there....

When Craig said the while assignment is look like the video before this he is only talking about this part:

while (( line = reader.readLine() != null)

You do not need the rest of the while part:

{
       String[] args = line.split("\\ |");//<-- you do not need this
       playSong(new Song(args[0]));//<--this actually needed here but then again please fix it you use the wrong syntax
     }

And also you need to modify the while statements. We are not talking about sorting file names or songs here. We are trying to pull available CustomerSupportReps from a queue. You need to check if one is available. This is how I will do the code for this challenge:

import java.util.ArrayDeque;
import java.util.Queue;

public class CallCenter {
  Queue<CustomerSupportRep> mSupportReps;

  public CallCenter(Queue<CustomerSupportRep> queue) {
    mSupportReps = queue;
  }

  public void acceptCustomer(Customer customer) {
    CustomerSupportRep csr;
    /********************************************
     * TODO (1) 
     * Wait until there is an available rep in the queue.
     * While there is not one available, playHoldMusic
     * HINT: That while assignmentcheck loop syntax we used to 
      *      read files seems pretty similar
     ********************************************
     */
    while((csr=mSupportReps.poll()) == null) {//<-- this is what Craig means by similar while assignment as video before
      playHoldMusic();
    }

    /********************************************
     * TODO (2) 
     * After we have assigned the rep, call the 
     * assist method and pass in the customer
     ********************************************
     */
    csr.assist(customer);

    /********************************************
     * TODO (3) 
     * Since the customer support rep is done with
     * assisting, put them back into the queue.
     ********************************************
     */
    mSupportReps.offer(csr);

  }

  public void playHoldMusic() {
    System.out.println("Smooooooth Operator.....");
  }

}

I hope this will help. Happy coding