silentkiler029

Java Home Work - Samir Sir - Postal Code

Dec 7th, 2021 (edited)
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.16 KB | None | 0 0
  1. // MainDoor.java
  2. import java.util.HashMap;
  3.  
  4. class PostalCode {
  5.     // properties
  6.     int code;
  7.     String area;
  8.    
  9.     void setPostalCode (String postArea, int postCode) {
  10.         code = postCode;
  11.         area = postArea;
  12.     }
  13. }
  14.  
  15. class Country {
  16.     String countryCode;
  17.     String subDomain;
  18.     String countryName;
  19.     String continent;
  20.     String alternateName;
  21. }
  22.  
  23. class Address {
  24.     // Properties
  25.     String houseName;
  26.     String area;
  27.     String city;
  28.     String division;
  29.    
  30.     Country country;
  31.     PostalCode postCode;
  32.    
  33.     // Actions / Functionality
  34.     public void createAddress(String hname, String areas, String cities, String divisions, Country countries, PostalCode postalCode){
  35.         houseName = hname;
  36.         area = areas;
  37.         city = cities;
  38.         division = divisions;
  39.         country = countries;
  40.         postCode = postalCode;
  41.     }
  42.    
  43.     public void showAddress() {
  44.         System.out.println("House Name : " + houseName);
  45.         System.out.println("Area : " + area);
  46.         System.out.println("Postal Code : " + postCode.code);
  47.         System.out.println("City : " + city);
  48.         System.out.println("Division : " + division);
  49.         System.out.println("Country : " + country.countryName);
  50.         System.out.println();
  51.     }
  52. }
  53.  
  54. public class MainDoor {
  55.    
  56.     private static HashMap <String, Country> initiateCountries(HashMap <String, Country> countries) {
  57.         Country country = new Country();
  58.         country.countryName = "Myanmar";
  59.         country.countryCode = "+089";
  60.         country.continent = "Asia";
  61.         country.subDomain = "mn";
  62.         country.alternateName = "Burma";
  63.        
  64.         countries.put("Myanmar", country);
  65.        
  66.         country = new Country();
  67.         country.countryName = "India";
  68.         country.countryCode = "+091";
  69.         country.continent = "Asia";
  70.         country.subDomain = "in";
  71.         country.alternateName = "Bharat";
  72.        
  73.         countries.put("India", country);
  74.        
  75.         country = new Country();
  76.         country.countryName = "Bangladesh";
  77.         country.countryCode = "+880";
  78.         country.continent = "Asia";
  79.         country.subDomain = "bd";
  80.         country.alternateName = "Bangladesh";
  81.        
  82.         countries.put("Bangladesh", country);
  83.        
  84.         return countries;
  85.     }
  86.    
  87.     private static HashMap <String, PostalCode> initiatePostalCodes(HashMap <String, PostalCode> postCodes) {
  88.         // adding postal code
  89.         PostalCode tempPostCode = new PostalCode();
  90.         tempPostCode.setPostalCode("Sylhet Sadar", 3100);
  91.         postCodes.put(tempPostCode.area, tempPostCode);
  92.        
  93.         tempPostCode = new PostalCode();
  94.         tempPostCode.setPostalCode("Akhalia", 3114);
  95.         postCodes.put(tempPostCode.area, tempPostCode);
  96.        
  97.         tempPostCode = new PostalCode();
  98.         tempPostCode.setPostalCode("KajolShah", 3110);
  99.         postCodes.put(tempPostCode.area, tempPostCode);
  100.        
  101.         tempPostCode = new PostalCode();
  102.         tempPostCode.setPostalCode("Jalalabad", 3107);
  103.         postCodes.put(tempPostCode.area, tempPostCode);
  104.        
  105.         tempPostCode = new PostalCode();
  106.         tempPostCode.setPostalCode("Sylhet Biman Bondor", 3102);
  107.         postCodes.put(tempPostCode.area, tempPostCode);
  108.        
  109.         return postCodes;
  110.     }
  111.    
  112.     public static void main(String[] args)
  113.     {
  114.         HashMap <String, Country> countries = new HashMap <String, Country>();
  115.         HashMap <String, PostalCode> postCodes = new HashMap <String, PostalCode>();
  116.         countries = initiateCountries(countries);
  117.         postCodes = initiatePostalCodes(postCodes);
  118.        
  119.        
  120.         Address shanto = new Address();
  121.         String houseName = "My Cool House";
  122.         String areaName = "Akhalia";
  123.         String cityName = "Sylhet Sadar";
  124.         String divisionName = "Sylhet";
  125.         String countryName = "Bangladesh";
  126.        
  127.         shanto.createAddress( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
  128.        
  129.         shanto.showAddress();
  130.        
  131.         Address mehraj = new Address();
  132.         houseName = "My Cool House";
  133.         areaName = "KajolShah";
  134.         cityName = "Sylhet Sadar";
  135.         divisionName = "Sylhet";
  136.         countryName = "Bangladesh";
  137.        
  138.         mehraj.createAddress( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
  139.        
  140.         mehraj.showAddress();
  141.        
  142.     }
  143. }
Add Comment
Please, Sign In to add comment