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

Jvalant Dave
Jvalant Dave
4,483 Points

Having trouble with the next challenge (Call center) ?

I seem to have the correct code for the challenge (based on another discussion question that has the same answer as me) but I keep getting a "Did you remember to call the assist method on the Customer Service Rep" message. I have tried refreshing the code challenge and I'm still getting the same message, even though I have called the assist method. Here is my code:

 /********************************************
 * 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
 ********************************************
 */
csr = mSupportReps.poll();
while ((csr = mSupportReps.poll()) == null){
  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.add(csr);
Jvalant Dave
Jvalant Dave
4,483 Points

I commented out the csr = mSupportReps.poll() line above the while loop and it worked! Not sure why, I guess the line was unnecessary but not sure why I was getting an failure on the challenge because of it...

4 Answers

Florian Tönjes
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Florian Tönjes
Full Stack JavaScript Techdegree Graduate 50,856 Points

Hey Jvalant,

the code failed because it removed the first csr from the queue, without letting him support a customer, and then never touching him again.

Regards, Florian

Jeff Wilton
Jeff Wilton
16,646 Points

You were very close, just remove this line - which was causing things to happen out of order.

csr = mSupportReps.poll();
Kourosh Raeen
Kourosh Raeen
23,733 Points

I agree with Florian Tönjes. If you want to keep the line before the loop change your code to:

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

  }

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

}
Jvalant Dave
Jvalant Dave
4,483 Points

Thanks guys! I understand why that line was incorrect now.