-2
\$\begingroup\$

I dont know why my code is not working at all. In my Eclipse there's no errors shown at all.

I want to use the id to print the name of my customers, and that's my goal

Customer[] custArray = { new Customer("Chen",35), new Customer("You",36) };


public Customer searchCustomerByID(int custID){
               for(Customer c:customers){
                 if(c.getID() == custID)
                   return c;
               }
               return null;
             }
````
\$\endgroup\$
  • 2
    \$\begingroup\$ my code is not working at all makes this question off-topic at Code Review@SE. Please heed How to create a Minimal, Complete, and Verifiable example at SO. \$\endgroup\$ – greybeard Apr 16 at 6:59
  • 1
    \$\begingroup\$ @greybeard: Actually, here we only want a CVE, a Complete and Verifiable Example. We want to have all the code rather than example code taken out of context. \$\endgroup\$ – Graipher Apr 16 at 9:46
  • \$\begingroup\$ (@Graipher: as I augmented the explication of mcve with the site I have been referring to, I think the Actually is uncalled for.) \$\endgroup\$ – greybeard Apr 16 at 9:48
  • 1
    \$\begingroup\$ @greybeard: Yes, that first sentence certainly helps. However I think linking to the SO mcve page is not the best way to show the OP how a question should look like on Code Review. IMO the link to our help center should be sufficient. Otherwise you would always have to specify which parts of the mcve page need to be explicitly ignored when posting here (namely the minimal part). \$\endgroup\$ – Graipher Apr 16 at 9:53
  • \$\begingroup\$ (As the question is entirely off-topic here, I tried to refer poster and question to SO.) \$\endgroup\$ – greybeard Apr 16 at 10:58
-1
\$\begingroup\$

You wrote this:

for (Customer c : customers)
{
    if (c.getID == customID) return c;
}

The array is called custArray. And the for-each is iterating over an array of Customers cales customers. So, the simple solution is to change customers to custArray! Hope that helps. ;)

EDIT: this should be on Stack Overflow.

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to Code Review. Please refuse to answer off-topic questions. \$\endgroup\$ – Heslacher Apr 16 at 4:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.