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

Can not get my code to pass!

I have tried everything, someone please help.

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) {
      csr = mSupportReps.poll();
      csr.assist(customer);
    }
     mSupportReps.add(CustomerSupportRep);
  }

  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

Dan Johnson
Dan Johnson
40,533 Points

Nested methods aren't a feature of Java (though you can create similar constructs), so declaring a new assist method won't work. It's also not needed; The assist functionality is built into the CustomerSupportRep class.

The rest of the code looks fine with the exception of one part which I've marked with a comment about the changes:

  public void acceptCustomer(Customer customer) {
     CustomerSupportRep csr;

     while(mSupportReps.isEmpty()) {
       playHoldMusic();
     } 

     csr = mSupportReps.poll();
     csr.assist(customer);

     // Put back the support rep instance instead of the class type.
     mSupportReps.add(csr);
  }

Thank you!