Java Java Data Structures Efficiency! Custom Serialization

Iván Martínez
Iván Martínez
11,278 Points

Help with "Did you remember to call the assist method on the CustomerSupportRep?" error.

The code challenge keeps asking if i did remember to call the assist method on CSR. What i'm doing wrong?

public void acceptCustomer(Customer customer) {
    CustomerSupportRep csr;

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

    do {
      playHoldMusic();
    } while((csr = mSupportReps.poll()) == null);


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

  }
Kareem Jeiroudi
Kareem Jeiroudi
14,981 Points

You solution works perfectly. The only thing you're missing is to keep checking for a new representative in the queue in the while loop, like this:

do {
playHoldMusic();
csr = mSupportReps.poll();
} while (csr == null);

3 Answers

Carlo Antonio Bilbao
Carlo Antonio Bilbao
24,112 Points

I used an if else statement instead. csr =mSupportReps.poll(); if (csr == null) { playHoldMusic(); } else { csr.assist(customer); mSupportRep.add(csr; }

Hope this helps

It helped me too. Thank you.

Kareem Jeiroudi
Kareem Jeiroudi
14,981 Points

Strange, although it says explicitly to use a while loop. I'm having the same problem as Iván Martínez.

Andrea Marloni
Andrea Marloni
8,436 Points

Or:

public void acceptCustomer(Customer customer) {
    CustomerSupportRep csr;
    csr = mSupportReps.poll();
    while (csr == null) {
      playHoldMusic();
      csr = mSupportReps.poll();
    }
    csr.assist(customer);
    mSupportReps.add(csr);
  }
George Georgiou
George Georgiou
4,540 Points

Consider using the .peek() method in the loop, before assigning any value to csr