I need to write a method for this:
** returns the customer with the specified id, or null if the
* customer is not registered at the branch
* @param id the customer's number
* @return the customer is registered with the branch,or null
**/
allCustomers is the HashSet of customers. So I need to return the customer in the HashSet that has the id specified in the parameter....
Its not something I want! Its a question on my University coursework. But yeah it sounds like HashMap would have done a better job, don't know why they chose HashSet.
Would this work:
public Customer getCustomer(int cNo)
{
for(Customer c: allCustomers){
if(c.getCustomerNo()==cNo){
return c;
}
}
return null;
}