Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Efficiency! Call Center Queue

I'm confused about this challenge.


I'm having trouble with this challenge. I think I'm doing it correctly, I kind of followed the same logic as adding songs to our Karaoke machine and then taking them out of the queue but this doesn't seem to work here. Unless I'm doing something wrong. Any tips?

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) {
    } csr = mSupportReps.poll();

     * 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.....");

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",
    System.out.println("Is there anything else I can help you with?");

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

public class Customer {
  private String mName;

  public Customer(String name) {
    mName = name;

  public String getName() {
    return mName;


2 Answers

Craig Dennis
Craig Dennis
Treehouse Teacher

In your while loop you are actually setting the csr variable and pulling it out. Therefore when the while loop ends, you have already set the csr value. You don't need to call it again, that is what is causing your error.

Good job!

Hope that helps!

Thanks Craig!

Totally missed that part :/.

Would you mind taking a look at the below question as well? I've searched on Stackoverflow and the Java documentation, it looks like I might have to do some sort of Casting, but I didn't see you do that in the video:


Hi All,

Actually I found the answer on the forum. In-case someone else is running into this. I was using .poll() to see if the queue was empty. But that also removes the CSR from the queue. Thus we must use .peek() in the beginning and if it is not null then remove from the queue.


while ((csr = mSupportReps.poll()) != null) { playHoldMusic(); } csr = mSupportReps.poll(); csr.assist(customer); mSupportReps.add(csr);

Solution: while(mSupportReps.peek() == null) { playHoldMusic(); } csr = mSupportReps.poll(); csr.assist(customer); mSupportReps.add(csr);

Thanks to Rob Bridges and Christopher Augg at this forum:


for clarifying this.