package hansen.playground; import java.util.*; /** * Customer.java * This class is a bean that is used for a faked customer lookup * The customers are implemented through a hash table * * @author Keld H. Hansen - 2001 */ public class Customer { private String id = ""; private String name = ""; private String address = ""; private boolean dataFound = false; private Person p1; private Person p2; private Hashtable persons; public Customer() { // Initilize the set of customers persons = new Hashtable(); p1 = new Person("Peter Hansen", "888 West blvd."); p2 = new Person("Joe Smith", "123 River drive."); persons.put("1", p1); persons.put("2", p2); } public String getId() { return id; } public String getName() { return name; } public String getAddress() { return address; } public boolean isDataFound() { return dataFound; } public void setId(String id) { this.id = id; } public void setName(String name) { this.name = name; } public void setAddress(String address) { this.address = address; } public int readCustomerInfo() { Person p = (Person)persons.get(id); if (p != null) { name = p.getName(); address = p.getAddress(); dataFound = true; return 1; } else { name = ""; address = ""; dataFound = false; return 0; } } public int updateCustomer() { Person p = (Person)persons.get(id); if (p != null) { p.setName(name); p.setAddress(address); dataFound = true; return 1; } else { return 0; } } public int deleteCustomer() { Person p = (Person)persons.remove(id); name = ""; address = ""; dataFound = false; if (p != null) { return 1; } else { return 0; } } public int createCustomer() { Person p = new Person(name, address); persons.put(id, p); dataFound = true; return 1; } }