?
Solved

Collection Examplw

Posted on 2004-10-27
7
Medium Priority
?
197 Views
Last Modified: 2010-03-31
Hi,

Would like an example of a collection class

Cheers
0
Comment
Question by:Cyart
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 12425003
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
 

Author Comment

by:Cyart
ID: 12425069
Have you got a basic main to test this with,just so I can see it working
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12425175
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 8

Assisted Solution

by:kiranhk
kiranhk earned 400 total points
ID: 12425654
check out the collections examples
http://javaalmanac.com/egs/java.util/pkg.html
0
 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 12428040
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12498244
did you find any of the suggestions useful?? havent heard from you for a long time
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12542780
8-)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question