• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what data structure is good for this problem ?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sounds like a good idea to me.
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You have to be odd to be #1 - Seuss. An odd little ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic