Cannot interpret compile time errors java?

^ cannot find symbol
symbol : method addMonthlyInterest()
location: class Customers[]
^ incompatible types
found : Customers
required: Customers[]
for (Customers[] customer: customers)
6 errors

here I have created an Account, Customers and Bank class.
In Account:
Customers[] customer;
In Bank:
Account[] account;

for (Customers[] customer: customers)
is trying to look at all customer elements in the customers array of type Customer.
What’s up?

The customers variable is a Customers array. In the for loop, if you want to refer to a specific element in customers, the variable representing it must be an object of type Customers, not an array of Customers. It should be:

for (Customers customer : customers)

For the Bank error, I’m guessing you tried to call the method addMonthlyInterest() on the entire array instead of just a single element. You should be instead be looping through the array and calling the method on each element that is iterated over.

(Also, as a mention for good coding convention, you shouldn’t be naming a class with a plural name unless it really is used to signify a group. If your class is only supposed to model one customer, then call it Customer. When you want an array of “Customer”s, you should just call the variable with the plural name, e.g. Customer[] customers.

Leave a Reply