I'm searching through a table for a customer with a matching name, if found then I want to return that customer, otherwise return null. The problem is I'm getting null all the time, I think my problem is with the if in the inner for loop.
public class testter {
public Customer isCustomerInTable(Customer[][] table, String customerName) {
for ( int r = 0; r < table.length; r++ ) {
for ( int c = 0; c < table[r].length; c++ ) {
if ( table[r][c].equals(customerName) ) {
return table[r][c];
}
}
}
return null;
}
}
My customer class:
class Costumer {
private String name;
public Customer() {
name = "";
}
public void setCostumerName(String name) {
this.name = name;
}
public String getCostumerName(){
return name;
}
}
Any ideas? Thanks