Results 1 to 3 of 3
-
How to set up this Class to use FOR-EACH loops?
NetBeans is giving me the error for Customers (underlined in my code) that "cannot find symbol". Does anyone know what am I doing wrong here? I need to be able to iterate through all instances of Customer :confused:Java Code:import java.util.*; import java.io.Serializable; public class Customers implements Iterable<Customers.Customer>, Serializable { public class Customer { ... //constructor Customer(params) { ... addCustomer(this); } } private Set<Customer> customerSet = new HashSet<Customer>(); public void addCustomer(Customer c) { customerSet.add(c); } public Iterator<Customer> getCustomers() { return customerSet.iterator(); } public Iterator<Customer> iterator() { return getCustomers(); } public Customer getCustomer(int cid) { for (Customer c:[COLOR="Red"][U]Customers[/U][/COLOR]) { if (c.id == cid) { return c; } } } }Last edited by ozzyman; 04-04-2011 at 10:28 PM.
-
Turns out this is the correct usage:
Java Code:public Customer getCustomer(int cid) { [COLOR="Red"]Customers myCustomers = new Customers();[/COLOR] Customer thisCustomer = new Customer(); for (Customer c:[COLOR="red"]myCustomers[/COLOR]) { if (c.id == cid) { thisCustomer = c; break; } } return thisCustomer; }
Problem solved. Thanks for looking.
-
Similar Threads
-
implementing an algorithm for shortest path problem in java
By thorobred in forum New To JavaReplies: 0Last Post: 03-20-2011, 01:17 AM -
Problem implementing ActionListener??
By ryanonnfire54 in forum New To JavaReplies: 3Last Post: 11-16-2010, 04:39 PM -
Problem Creating/implementing Objects
By ramathews in forum New To JavaReplies: 2Last Post: 02-25-2010, 03:42 AM -
problem with implementing list
By timkd127 in forum New To JavaReplies: 3Last Post: 04-13-2009, 03:54 AM -
java.util
By Java Tutorial in forum Java TutorialReplies: 1Last Post: 02-07-2008, 01:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks