ΠΠΎΠ»Π°Π³Π°Ρ, ΡΡΠΎ - ΡΠΎ Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π½ΡΠΌ Π½ΠΎΠΌΠ΅ΡΠΎΠΌ Π½Π΅ ΡΠ°ΠΊ, Π½ΠΎ Π½Π΅ Π²ΠΈΠΆΡ, ΡΡΠΎ
package com.javarush.task.task19.task1903;
/*
ΠΠ΄Π°ΠΏΡΠ°ΡΠΈΡ Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΈΡ
ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡΠΎΠ²
*/
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static Map<String, String> countries = new HashMap<String, String>();
static {
countries.put("UA", "Ukraine");
countries.put("RU", "Russia");
countries.put("CA", "Canada");
}
public static void main(String[] args) {
}
public static class IncomeDataAdapter implements Contact, Customer{
private IncomeData data;
public IncomeDataAdapter(IncomeData data){
this.data = data;
}
@Override
public String getCompanyName() {
return this.data.getCompany();
}
@Override
public String getCountryName() {
return
countries.get(data.getCountryCode());
}
@Override
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
String phone = String.valueOf(data.getPhoneNumber());
String countryCode = "(0" + phone.substring(0, 1) + ")";
String numbers = phone.substring(2, 4) + "-" + phone.substring(5, 6) + "-" + phone.substring(7, 8);
String phoneNumber = "+" + data.getCountryPhoneCode() + countryCode + numbers;
return phoneNumber;
}
}
public static interface IncomeData {
String getCountryCode(); //For example: UA
String getCompany(); //For example: JavaRush Ltd.
String getContactFirstName(); //For example: Ivan
String getContactLastName(); //For example: Ivanov
int getCountryPhoneCode(); //For example: 38
int getPhoneNumber(); //For example: 501234567
}
public static interface Customer {
String getCompanyName(); //For example: JavaRush Ltd.
String getCountryName(); //For example: Ukraine
}
public static interface Contact {
String getName(); //For example: Ivanov, Ivan
String getPhoneNumber(); //For example: +38(050)123-45-67
}
}