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 trialJay Bhatt
6,502 PointsHow do I figure out if the queue is available? And how do I call the assist method withoutgetting the "non-static"error?
Please help, I have been staring at this for hours.
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();
}
/********************************************
* 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
********************************************
*/
if (mSupportReps.size() > 0) {
CustomerSupportRep.assist(customer);
}
/********************************************
* 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;
}
}
2 Answers
markmneimneh
14,132 PointsHello
Please see this part of the code you pasted
if (mSupportReps.size() > 0) { CustomerSupportRep.assist(customer); }
You don't call the Class, you call the instance of the class ...
as in csr..assist(customer);
I think this should solve the error
if this answers you question, please mark the question as answered.
Thanks
markmneimneh
14,132 PointsHello
CustomerSupportRep csr;
does not initialize csr, it simply create a reference to an instance of type CustomerSupportRep. At this point, this is a pointer to null.
to initlialize csr, you have to call a constructor as in CustomerSupportRep csr = new CustomerSupportRep();
take a look here to see what other follow student is doing for this partivlar line
Hope this helps;
Jay Bhatt
6,502 PointsJay Bhatt
6,502 PointsThis rid the error of the static one. However I have new issue now, it says the csr has not been initialized. However if you see in the code, it is initialized hence we are using it as an instance of the class CustomerSupportRep. How do I fix this issue?