title: Searching an arraylist of objects for a user given phrase
body: <p>My program has a user add a customer name and customer phone number to an arraylist. Then if the user wants they can search(the arraylist) for a customer depending on what they enter in. If the user enters a name of "nate" and only types in nat to search. It is supposed to display all matches that contain nat.</p>
  
  <p>I can't seem to use the for loop correctly and if it does. It only matches exact content when I use the .equals method.</p>
  
  <hr>
  
  <p>Now that I have updated the .equals to .contains. The new problem is that the 
  for (Customer c : customers ) is not working. Customer is my class that creates the object, customers is the arraylist containing the Customer objects. </p>
  
  <p>At: for (Customer c :
  Error message says: </p>
  
  <blockquote>
    <p>Error:(107, 31) java: incompatible types: java.lang.Object cannot be converted to Customer></p>
  </blockquote>
  
  <pre><code>public class CustomerDirectory
  {
      //Shorten Scanner
      static Scanner keyboard = new Scanner(System.in);
  
      static ArrayList customers = new ArrayList();
  
  
      public static void main(String[] args)
   ......
   .......
  </code></pre>
  
  <hr>
  
  <p>method in main class that adds a customer name and phone number to the arraylist.</p>
  
  <pre><code>    public static void addCustomer()
  {
  
      System.out.print("Enter new name: ");
      String name = keyboard.nextLine();
      name = keyboard.nextLine();
      System.out.print("Enter new phone number: ");
      String number = keyboard.nextLine();
  
      Customer newCustomer = new Customer(name, number);
      customers.add(newCustomer);
  
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    public static void findCustomer()
  {
      System.out.print("Enter name of customer to find: ");
      String findName = keyboard.nextLine();
      findName = keyboard.nextLine();
      if (findName.equals(" "))
      {
          System.out.println("You did not enter a name.");
      }
      else
      {
          for (Customer c : customers )
          {
              if (c.getCustomerName().contains(findName) )
              {
                  System.out.println(c.getCustomerName());
              }
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Class that creates the objects to go into the array list.
      class Customer
      {
      static String customerName;
      String telePhone;</p>
  
  <pre><code>public Customer(String customerName, String telePhone)
  {
      setCustomerName(customerName);
      setTelePhone(telePhone);
  }
  
  public static String getCustomerName()
  {
      return customerName;
  }
  
  public void setCustomerName(String customerName)
  {
      //Make the user input lowercase
      customerName = customerName.toLowerCase();
      if (customerName.equals(""))
      {
          System.out.println("You did not enter a name. Did not create new                      
      customer.");
      }
      else if (customerName.length() &gt; 25)
      {
          this.customerName = customerName.substring(0, 25);
      }
      else
      {
          this.customerName = customerName;
      }
  
  }
  
  public String getTelePhone()
  {
      return telePhone;
  }
  
  public void setTelePhone(String telePhone)
  {
      if (telePhone.equals(""))
      {
          System.out.println("You did not enter a telephone number. Did not   
      create new customer.");
      }
      else
      {
          this.telePhone = telePhone;
      }
  }
  }
  </code></pre>