• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Collection Examplw

Hi,

Would like an example of a collection class

Cheers
0
Cyart
Asked:
Cyart
3 Solutions
 
CEHJCommented:
Here's one that (just for instance ;-)) models a Bank having a collection of Customer

import java.util.*;

public class Bank {
      private Map customers;
      // need other attributes pertaining to the bank itself
      
      public Bank() {
            customers = new HashMap();
      }
      
      public void addCustomer(Customer c) {
            customers.put(c.getId(), c);
      }
      
      public Customer getCustomer(Integer id) {
            return (Customer)customers.get(id);
      }
      
      // need a remove, getCustomers too
      
      public String toString() {
            return customers.toString();
      }

}
0
 
CyartAuthor Commented:
Have you got a basic main to test this with,just so I can see it working
0
 
CEHJCommented:
Well, first you need to create a Customer class then that's fairly trivial. Do that first. Clue: the relationship between Bank/Customer is the same as Customer/Account
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
kiranhkCommented:
check out the collections examples
http://javaalmanac.com/egs/java.util/pkg.html
0
 
objectsCommented:
0
 
kiranhkCommented:
did you find any of the suggestions useful?? havent heard from you for a long time
0
 
CEHJCommented:
8-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now