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

Don't know the answer. Please help.

Can someone let me see their code.

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;
    while(mSupportreps.isEmpty()) {
      playHoldMusic();
    } 
    public void Set<CustomerSupportRep>assist(Customer Customer) {
      Customer customer=mSupportReps.poll();

    }
     mSupportsREps.addCustomerSupportReps();
  }


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

}

1 Answer

Allan Clark
Allan Clark
10,810 Points
public void acceptCustomer(Customer customer) {
    CustomerSupportRep csr;
    while(mSupportreps.isEmpty()) {
      playHoldMusic();
    } 
    public void Set<CustomerSupportRep>assist(Customer Customer) {
      Customer customer=mSupportReps.poll();

    }
     mSupportsREps.addCustomerSupportReps();
 }

Remember capitalization is important.

The first step (while loop) in the method is mostly correct (mSupportReps). Now after the while loop finishes we know a CustomerSupportRep is available in the queue. Craig so kindly added a csr variable for us to use when grabbing the rep out of the queue. Do that by using the poll method provided in the Queue class.

csr = mSupportReps.poll();

Next the csr needs to assist the customer. Luckily we have an assist() method in the CustomerSupportRep class that accepts a Customer as an argument.

csr.assist(customer);

Finally we need to put the rep back into the queue. That would be using the add method from the Queue class.

mSupportReps.add(csr);

*Side note: When creating forum questions try using specifics. Provide the code for where you think the issue is, maybe add the errors you are getting. Ask specific questions. The more information you provide the easier and faster the question will be answered. Help us help you! :D

Hope this helps, let me know if you are still getting errors.