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 trialMark Miller
45,831 PointsThe preview looks right. Why does it say I am not calling the assist method on the customer support representative?
Everything seems fine. I don't see a problem.
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
********************************************
*/
do {
playHoldMusic();
} while (mSupportReps.poll() == null);
/********************************************
* TODO (2)
* After we have assigned the rep, call the
* assist method and pass in the customer
********************************************
*/
csr = mSupportReps.poll();
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.....");
}
}
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;
}
}
public class Customer {
private String mName;
public Customer(String name) {
mName = name;
}
public String getName() {
return mName;
}
}
1 Answer
Grigorij Schleifer
10,365 PointsHi Mark,
your code is almost done.
For the first challenge you better use peek() instead poll(). Don't poll the queue, peek it, else you will lose the csr.
And you have used the do while loop. This loop will run the playHoldMusic() method at least once, no matter if the while condition is true or not. So the result of the condition could say that there is no csr inside the queus, but play music once.
Task 2: looks good.
Task 3: You will nee to add the csr back to the queue (that's beeing peeked). I thing there is no offer() method here.
mSupportReps.add(csr);
Keep on doing the good job
Grigorij
Shadd Anderson
Treehouse Project ReviewerShadd Anderson
Treehouse Project ReviewerHad no idea what "peek" was until you pointed it out. I had the exact same error and it was driving me crazy lol.
Thanks!
Grigorij Schleifer
10,365 PointsGrigorij Schleifer
10,365 PointsHey Shadd,
glad I could help