Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MainDoor.java
- import java.util.HashMap;
- class PostalCode {
- // properties
- int code;
- String area;
- void setPostalCode (String postArea, int postCode) {
- code = postCode;
- area = postArea;
- }
- }
- class Country {
- String countryCode;
- String subDomain;
- String countryName;
- String continent;
- String alternateName;
- }
- class Address {
- // Properties
- String houseName;
- String area;
- String city;
- String division;
- Country country;
- PostalCode postCode;
- // Actions / Functionality
- public void createAddress(String hname, String areas, String cities, String divisions, Country countries, PostalCode postalCode){
- houseName = hname;
- area = areas;
- city = cities;
- division = divisions;
- country = countries;
- postCode = postalCode;
- }
- public void showAddress() {
- System.out.println("House Name : " + houseName);
- System.out.println("Area : " + area);
- System.out.println("Postal Code : " + postCode.code);
- System.out.println("City : " + city);
- System.out.println("Division : " + division);
- System.out.println("Country : " + country.countryName);
- System.out.println();
- }
- }
- public class MainDoor {
- private static HashMap <String, Country> initiateCountries(HashMap <String, Country> countries) {
- Country country = new Country();
- country.countryName = "Myanmar";
- country.countryCode = "+089";
- country.continent = "Asia";
- country.subDomain = "mn";
- country.alternateName = "Burma";
- countries.put("Myanmar", country);
- country = new Country();
- country.countryName = "India";
- country.countryCode = "+091";
- country.continent = "Asia";
- country.subDomain = "in";
- country.alternateName = "Bharat";
- countries.put("India", country);
- country = new Country();
- country.countryName = "Bangladesh";
- country.countryCode = "+880";
- country.continent = "Asia";
- country.subDomain = "bd";
- country.alternateName = "Bangladesh";
- countries.put("Bangladesh", country);
- return countries;
- }
- private static HashMap <String, PostalCode> initiatePostalCodes(HashMap <String, PostalCode> postCodes) {
- // adding postal code
- PostalCode tempPostCode = new PostalCode();
- tempPostCode.setPostalCode("Sylhet Sadar", 3100);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode();
- tempPostCode.setPostalCode("Akhalia", 3114);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode();
- tempPostCode.setPostalCode("KajolShah", 3110);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode();
- tempPostCode.setPostalCode("Jalalabad", 3107);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode();
- tempPostCode.setPostalCode("Sylhet Biman Bondor", 3102);
- postCodes.put(tempPostCode.area, tempPostCode);
- return postCodes;
- }
- public static void main(String[] args)
- {
- HashMap <String, Country> countries = new HashMap <String, Country>();
- HashMap <String, PostalCode> postCodes = new HashMap <String, PostalCode>();
- countries = initiateCountries(countries);
- postCodes = initiatePostalCodes(postCodes);
- Address shanto = new Address();
- String houseName = "My Cool House";
- String areaName = "Akhalia";
- String cityName = "Sylhet Sadar";
- String divisionName = "Sylhet";
- String countryName = "Bangladesh";
- shanto.createAddress( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
- shanto.showAddress();
- Address mehraj = new Address();
- houseName = "My Cool House";
- areaName = "KajolShah";
- cityName = "Sylhet Sadar";
- divisionName = "Sylhet";
- countryName = "Bangladesh";
- mehraj.createAddress( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
- mehraj.showAddress();
- }
- }
Add Comment
Please, Sign In to add comment