Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hashtableTask;
- import java.util.*;
- public class App {
- public static void add(Hashtable<String, Queue<String>> hts,String name,String queue) {
- hts.get(queue).add(name);
- }
- public static void done(Hashtable<String, Queue<String>> hts,String queue, int numIt) {
- for(int i=0;i<numIt;i++)
- hts.get(queue).poll();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Hashtable<String, Queue<String>> ht = new Hashtable<String, Queue<String>>();
- Queue<String> qBank = new PriorityQueue<String>();
- Queue<String> qPost = new PriorityQueue<String>();
- Queue<String> qPay = new PriorityQueue<String>();
- ht.put("bank", qBank);
- ht.put("post",qPost);
- ht.put("pay",qPay);
- // add to bank
- ht.get("bank").add("Tzahi");
- add(ht,"Lorem","bank");
- add(ht,"Ipsum","bank");
- add(ht,"Dolor","bank");
- add(ht,"Sit","bank");
- add(ht,"elit","bank");
- add(ht,"Amet","bank");
- // add to post
- add(ht,"Sed","post");
- add(ht,"Do","post");
- add(ht,"Tempor","post");
- add(ht,"Labore","post");
- add(ht,"Dolore","post");
- add(ht,"Magna","post");
- add(ht,"Aliqua","post");
- // add to pay
- add(ht,"Enim","pay");
- add(ht,"Minim","pay");
- add(ht,"Quis","pay");
- add(ht,"Nostrud","pay");
- add(ht,"Ullamco","pay");
- add(ht,"Aute","pay");
- add(ht,"Anim","pay");
- // 2 uses for bank
- done(ht, "bank", 2);
- // 3 uses for post
- done(ht, "post", 3);
- // 1 use for post
- done(ht, "pay", 1);
- Set<String> keys = ht.keySet();
- for(String key : keys) {
- System.out.print("Values in "+key +":");
- while(!ht.get(key).isEmpty()) {
- System.out.print(ht.get(key).poll()+",");
- }
- System.out.println();
- }
- /*
- System.out.println(ht.get("bank"));
- System.out.println(ht.get("post"));
- System.out.println(ht.get("pay"));
- */
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement