silentkiler029

Java - CW - 8 December 2021

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