Java Java Data Structures Efficiency! Call Center Queue

Aleksander Henriksen
Aleksander Henriksen
3,059 Points

Call Center Queue

Hello.

Im trying to do the Call Center Queue assingemt, but i say that there are som errors when i run it and i haven't chanced anything where it says error.

JavaTester.java:69: error: illegal start of expression import java.util.ArrayDeque; ^

JavaTester.java:69: error: not a statement import java.util.ArrayDeque; ^

JavaTester.java:70: error: illegal start of expression import java.util.Queue; ^

JavaTester.java:70: error: not a statement import java.util.Queue; ^

JavaTester.java:72: error: illegal start of expression public class CallCenter { ^

5 errors

That's the error that it gives me, and i do not understand what is wrong there.

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;

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

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

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

  }

  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

Tonnie Fanadez
Tonnie Fanadez
UX Design Techdegree Graduate 21,841 Points

Aleksander Henriksen

This is what worked out for me, see my code and comments.

public void acceptCustomer(Customer customer) {

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

// you need to work with queue.size() which returns number of Reps in the queue
while (mSupportReps.size() == 0) {

    playHoldMusic();

}

/********************************************
 * TODO (2)
 * After we have assigned the rep, call the
 * assist method and pass in the customer
 ********************************************

 */
//to avoid a null pointer exception intialize the Rep here.
CustomerSupportRep csr = mSupportReps.poll();
csr.assist(customer);

//takes off the Rep from queue of available Reps
mSupportReps.poll();

/********************************************
 * TODO (3)
 * Since the customer support rep is done with
 * assisting, put them back into the queue.
 ********************************************

 */

//adds the Rep back to the queue
mSupportReps.add(csr);

}