I have a customer object with three properties: last name, first name, and SIN number
If the user enters the customer's last name and first name, and the object is found in the arraylist, the objects gets removed.
private static void deleteCustomer (String lastName, String firstName, List<Customer> accounts)
{
for (int i = 0; i < accounts.size(); i++)
{
accounts.get(i);
public int compare (Customer c1, Customer c2)
{
Customer customerOne = (Customer) c1;
Customer customerTwo = (Customer) c2;
if (lastName.equals(CustomerOne.getLastName()) && firstName.equals(CustomerOne.getFirstName()))
{
}
}
}
}
If two customers have the same first and last name, the user is asked to enter the SIN number, that's why I have the compare method. I'm not sure what to do after this.
Updated method:
public static void deleteCustomer (String lastName, String firstName, List<Customer> accounts)
{
for (Iterator<Customer> iterator = accounts.iterator(); iterator.hasNext();)
{
Customer customer = iterator.next();
if(lastName.equals(customer.getLastName()) && firstName.equals(customer.getFirstName()))
{
iterator.remove();
}
}
}
This works, but it removes all customers with the same first and last name
comparemethod, think about where to place it. Hint: inside another method is not a good place.Yes, it compiles.No, it doesn't. The updated code maybe does, but not the first one.