fahad005

Untitled

Dec 7th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. package postalcode;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. public class Main {
  7.  
  8.     HashMap<String, PostalCode> hm = new HashMap<String, PostalCode>();
  9.  
  10.     Main() {
  11.         createPostalCode();
  12.         printPostalCode();
  13.     }
  14.  
  15.     public void createPostalCode() {
  16.         PostalCode pc;
  17.        
  18.         pc = new PostalCode("Sakil", "Chandpur", "Kachua", "Kachua", "3630");
  19.         hm.put("Sakil", pc);
  20.  
  21.         pc = new PostalCode("Sumonta", "Narayanganj", "Bandar", "Nabiganj", "1412");
  22.         hm.put("Sumonta", pc);
  23.  
  24.         pc = new PostalCode("Fahad", "Dhaka", "Sabujbag", "Basabo TSO", "1214");
  25.         hm.put("Fahad", pc);
  26.     }
  27.  
  28.     public void printPostalCode() {
  29.         PostalCode pc;
  30.  
  31.         System.out.println("\n...Printing Postal Codes...");
  32.         for (Map.Entry m : hm.entrySet()) {
  33.             pc = new PostalCode(hm.get(m.getKey()));
  34.         }
  35.     }
  36.  
  37.     public static void main(String[] args) {
  38.  
  39.         new Main();
  40.     }
  41. }
  42.  
  43.  
  44.  
  45.  
  46. package postalcode;
  47.  
  48. // district, thana, sub office, post code
  49. public class PostalCode {
  50.  
  51.     String name;
  52.     String district;
  53.     String thana;
  54.     String subOffice;
  55.     String postCode;
  56.  
  57.     PostalCode(PostalCode p) {
  58.         printPostalCode(p);
  59.     }
  60.    
  61.     PostalCode(String n, String dis, String th, String so, String pc) {
  62.         createPostalCode(n, dis, th, so, pc);
  63.     }
  64.  
  65.     public void createPostalCode(String n, String dis, String th, String so, String pc) {
  66.         name = n;
  67.         district = dis;
  68.         thana = th;
  69.         subOffice = so;
  70.         postCode = pc;
  71.     }
  72.  
  73.     public void printPostalCode(PostalCode p) {
  74.         System.out.println("");
  75.  
  76.         System.out.println("Name       : " + p.name);
  77.         System.out.println("District   : " + p.district);
  78.         System.out.println("Thana      : " + p.thana);
  79.         System.out.println("Sub Office : " + p.subOffice);
  80.         System.out.println("Post Code  : " + p.postCode);
  81.  
  82.         System.out.println("");
  83.     }
  84. }
  85.  
  86.  
Add Comment
Please, Sign In to add comment