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! While you're at it, check out some resources Treehouse students have shared here.

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 - Retired Efficiency! Call Center Queue

Challenge "Efficiency"

Meh I kinda don't get it to run.

I would like to see how the author adds the CSR to the Queue so I can define better why this isn't working.

I created a while-loop which plays that hold music. But just as long as there is nothing within the queue (queue.peek() == null).

Everything what comes after the while-loop expects that the queue is not empty. And since the while-loop skipped that has to be true.

Where am I missing here (AGAIN!!!!!!!!) :)

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;
    /********************************************
     * 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(mSupportReps.peek() == null){
          playHoldMusic();
    }
    csr = mSupportReps.poll();
    csr.assist(customer);
    mSupportReps.add(csr);




    /********************************************
     * 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;
  }

}

3 Answers

Christopher Augg
Christopher Augg
21,223 Points

Hello Patrick,

You are very close! The key element you are missing is from the HINT in the comments

  • HINT: That while assignment check loop syntax we used to
  • read files seems pretty similar

In the video, Craig showed how to do an assignment operation within the while ((assignment) == null)

I hope that helps as it is the only issue I see with you current code. Please let me know if you need a more detailed explanation.

Thanks bro...actually I thought that couldn't be the problem because semantically the result would be the same...that's what I thought... seems that a "HINT" is actually an objective for the challenge

Craig Dennis
Craig Dennis
Treehouse Teacher

Doh you broke my mock! I'll fix it, your code was correct! Thanks for the patience!

Meh nvm these little things are nothing compared to the positive aspects u guys deliver

Craig Dennis
Craig Dennis
Treehouse Teacher

K, it's fixed now to allow peeking and using isEmpty. Thanks for uncovering the bug!

J.D. Sandifer
J.D. Sandifer
18,813 Points

Craig, shouldn't this work, too? It compiled and seems supported in the Java Docs.

while(mSupportReps.size() == 0){
          playHoldMusic();
    }