| Author |
what data structure is good for this problem ?
|
steve francisco
Ranch Hand
Joined: Jan 26, 2005
Posts: 46
|
|
Thinking about a Giant food store product. Each has a product code associated with it. The food is grouped by big groups then by smaller groups. For example: Milk (code: 01) whole milk (code 01-11) skim milk (code 01-12) Bread (code: 02) white bread (code 02-11) .... (code 02-12) Cheese (code: 03) swiss cheese (code 03-11) ... And for each product, we need its price, quantity, location, etc. User can pick from the lists and I need to display tables for the products they pick and it has to be grouped at the "2-digit" code level, i.e make a table for "milk" followed a table for "bread", etc. I think of using "Hashmap" and the key is the "2-digit" code (like 01, 02, 03), for each key, there is an Arraylist associated with it. e.g. for "01" the arraylist includes few elements, each element includes the "4-digit" code, price, quantity. So when I print the tables, I iterate through the keys, for each key, I create a table displaying the Arraylist. Is this a good idea or do you have better suggestion ?
|
 |
Neeraj Dheer
Ranch Hand
Joined: Mar 30, 2005
Posts: 225
|
|
|
sounds like a good idea to me.
|
 |
Chengwei Lee
Ranch Hand
Joined: Apr 02, 2004
Posts: 884
|
|
If your key contains just the code, how would you retrieve the big group name? from another look-up table? How about having a POJO to have 2 instance variables: a String to contain the big group name & an ArrayList to contain elements.
|
SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
|
 |
 |
|
|
subject: what data structure is good for this problem ?
|
|
|