I am creating a customer manager application for a Java course. I have it separated as per the requirements into 3 packages. The first package has a class called Customer, which models a customer and it's instance variables, such as customerID. The second package is a customer database that includes an ArrayList. The third package is going to be a menu driven UI that will allow the user to choose between 4 options. Currently, I am stuck trying to write a method that will search through the list for a given customerID and return a Customer object.
In the customer database class, I am getting the customerID from the user within the method. Then, I am running a for loop that should traverse the method to see if the customerID is found. I am having issues on how to return a customer object if the id is a match.
public Customer searchCustomer(String customerID) {
System.out.println("Enter customer ID you want to find:");
customerID = scnr.next();
Customer c;
for (int i = 0, i < customerList.size(); i++ {
c = customerList.get(i);
if (customerList.get(i).equals(customerID) {
String foundID = customerID;
}
}
}
I want to return Customer c at the end of the method, but cannot figure out how to do this.