Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ShantoDoesPracticeHere;
- import java.util.HashMap;
- class PostalCode {
- // properties
- int code;
- String area;
- //constructor
- public PostalCode() {
- this.code = -1;
- this.area = "";
- }
- public PostalCode (String area, int code) {
- this.code = code;
- this.area = area;
- }
- }
- class Country {
- // properties
- String countryName, countryCode, subDomain, continent, alternateName;
- public Country() {
- countryName = "";
- subDomain = "";
- countryCode = "";
- continent = "";
- alternateName = "";
- }
- public Country(String countryName, String countryCode, String subDomain, String continent, String alternateName) {
- this.countryName = countryName;
- this.countryCode = countryCode;
- this.subDomain = subDomain;
- this.continent = continent;
- this.alternateName = alternateName;
- }
- }
- class Address {
- // Properties
- String houseName, area, city, division;
- PostalCode postCode;
- Country country;
- // Actions / Functionality
- public Address(){
- this.houseName = "";
- this.area = "";
- this.city = "";
- this.division = "";
- this.country = new Country();
- this.postCode = new PostalCode();
- }
- public Address(String houseName, String area, String city, String division, Country country, PostalCode postCode){
- this.houseName = houseName;
- this.area = area;
- this.city = city;
- this.division = division;
- this.country = country;
- this.postCode = postCode;
- }
- 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("Myanmar", "+089", "Asia", "mn", "Burma");
- countries.put("Myanmar", country);
- country = new Country("India", "+091", "Asia", "in", "Bharat");
- countries.put("India", country);
- country = new Country("Bangladesh", "+880", "Asia", "bd", "Bangladesh");
- countries.put("Bangladesh", country);
- return countries;
- }
- private static HashMap <String, PostalCode> initiatePostalCodes(HashMap <String, PostalCode> postCodes) {
- // adding postal code
- PostalCode tempPostCode = new PostalCode("Sylhet Sadar", 3100);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode("Akhalia", 3114);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode("KajolShah", 3110);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode("Jalalabad", 3107);
- postCodes.put(tempPostCode.area, tempPostCode);
- tempPostCode = new PostalCode("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);
- // Shanto's Address
- String houseName = "Shanto\'s Cool House";
- String areaName = "Akhalia";
- String cityName = "Sylhet Sadar";
- String divisionName = "Sylhet";
- String countryName = "Bangladesh";
- Address shanto = new Address( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
- shanto.showAddress();
- // Mehraj's Address
- houseName = "Mehraj\'s Cool House";
- areaName = "KajolShah";
- cityName = "Sylhet Sadar";
- divisionName = "Sylhet";
- countryName = "Bangladesh";
- Address mehraj = new Address( houseName, areaName, cityName, divisionName, countries.get(countryName), postCodes.get(areaName) );
- mehraj.showAddress();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment