• 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

Collections Queries in Java.

 
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have below questions in Collections with respect to Java.

1> Suppose i have SSN(Social Security Number) as Key in Hashmap,The Value in HashMap being a combination of (customer name,customer address,customer pincode)

HashMap [key,Value]-->[SSN,(customer name,customer address,customer pincode)]

what datastructure i would use for the above implementation in Java and how would i retrieve customer details(name,address,pincode) based on SSN.Example for the above implementation provided will be helpful.


2> I have HashMap of [Key,Value] pair -> [bank account number,telephone no]

HashMap has got 3 entries
Ex:HashMap m = new HashMap();
m.put("12345","08026583026");
m.put("12346","08026583027");
m.put("12347","08026583028");

How do i retrieve telephone number based on bank account number,assume user inputs 12347 and the the result should be 08026583028 ??Example for the above implementation provided will be helpful.??



3> I have HashMap of [Key,Value] -> [telephone no,bank account number]

HashMap has got 3 entries
Ex:HashMap m = new HashMap();
m.put("08026583026","12345");
m.put("08026583027","12346");
m.put("08026583028","12347");
How do i retrieve bank account number based on telephone number,assume user inputs 08026583028 and the the result should be 12347 ??Example for the above implementation provided will be helpful.??

4> Give the Implementation /Algorithm to control 3 elevators in Core Java ??

Help provided will ne highly appreciated.

--
Deepak Lal
 
Ranch Hand
Posts: 84
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Deepak, the approach below can be used for 1,2,3.

You could create a class Customer that has a (name,address,pincode) properties in it, even the SSN. Then put the SSN as key in the map. Like this
Map.put(SSN,customerInstance).

regards,
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For 1: Do you know how to create a simple class in Java with instance fields and accessor methods?

For 2-3: I would look to the API of java.util.HashMap. You should be able to find a method that takes a key as a parameter and returns the corresponding object that was stored in the Map.

For 4: You'll have to work that out on your own. We don't do other peoples homework around here.
 
Deepak Lal
Ranch Hand
Posts: 603
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Angel and Garett,
Can you give me a example on how to proceed for Question 1,2,3.
I'm finding it a bit difficult to implement.If you can provide me with the implementation for the same.it would be helpful.

Help provided will be highly appreciated.

--
Deepak Lal
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Show Some Effort. Problems 2 and 3 are basically the same (how to get the value for a key) and Garrett has given you a hint to find the single method you need for this.

And I can't believe you don't know how to create the Customer class Angel has described. You've been on this board long enough to at least be able to create such a simple thing.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic