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 trialKenneth Phillips
Courses Plus Student 10,188 PointsCall Center Java Application
This is the error:
Seems like you played on hold music when there was a rep available.
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;
do {
playHoldMusic();
} while(mSupportReps == null);
csr = mSupportReps.poll();
csr.assist(customer);
mSupportReps.add(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
********************************************
*/
/********************************************
* 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",
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
Simon Coates
28,694 Pointsthe following snippet seemed to work:
CustomerSupportRep csr;
while ( (csr = mSupportReps.poll()) == null) {
playHoldMusic();
}
csr.assist(customer);
mSupportReps.add(csr);
while(mSupportReps == null); is faulty, I think. and it didn't seem to like the use of the do while loop.
Kenneth Phillips
Courses Plus Student 10,188 PointsKenneth Phillips
Courses Plus Student 10,188 PointsThanks I get how you did it. Much thanks especially since I've posted this 3 times and no one could make it work until now.
Simon Coates
28,694 PointsSimon Coates
28,694 PointsI was a little worried i hadn't posted enough explanation. But if you got it, then cool. FYI, it can take a while to get a response to java programming problems sometimes, so it can save time to look through prior answers. I'm not sure there's a direct link from challenges, so you might need to search for a forum post with an error message (in treehouse or via google) and then click the breadcrumb link (in this case Call Center Queue takes you to https://teamtreehouse.com/community/code-challenge:7842 ). Unless you're doing a brand new course, you can typically be confident that if something tripped you up, it will have tripped up a bunch of other people.