so I have class Customer and class Bank , a bank class has methods of adding Customer to an arraylist of Customers , and also must have a method to search a Customer in an arraylist and delete it (Remove from arraylist) , How can I do it?
Bank class -
private ArrayList<Customer> customers = new ArrayList<>();
public void addCustomer(String name){
Customer customer = new Customer(name);
customers.add(customer);
System.out.println("new customer " + customer.getName() + " added");
}
public void deleteAccount(String name){
}
Customer class -
private String name;
private double balance;
public Customer(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return "Customer " +
"name :'" + name + '\'' +
'}';
}
Main -
public static void deleteAccount(){
System.out.println("Enter the name you want to delete");
String name = scanner.nextLine();
scanner.nextLine();
bank.deleteAccount(name);
}
As you can see, the main class has method which takes input type String from user and then calles Bank class's method of deleteAccount with that input , but I don't know how to proceed with the deleteAccount method, how to make it work ?
I need something that firstly checks if the user input is in the Arraylist, and then remove it from there if there is.
I do realize that input is String and Arraylist is Customer instances , but Customer only takes String name in constractor, so can I make it work this way?