Created
July 16, 2016 22:54
-
-
Save josinSbazin/ce05dee3671c9f22f71023250fcefb31 to your computer and use it in GitHub Desktop.
level19.lesson03.task03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level19.lesson03.task03; | |
/* Адаптация нескольких интерфейсов | |
Адаптировать IncomeData к Customer и Contact. | |
Классом-адаптером является IncomeDataAdapter. | |
Инициализируйте countries перед началом выполнения программы. Соответствие кода страны и названия: | |
UA Ukraine | |
RU Russia | |
CA Canada | |
Дополнить телефонный номер нулями до 10 цифр при необходимости (смотри примеры) | |
Обратите внимание на формат вывода фамилии и имени человека | |
*/ | |
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 class IncomeDataAdapter implements Customer, Contact { | |
private IncomeData incomeData; | |
public IncomeDataAdapter (IncomeData incomeData) { | |
this.incomeData = incomeData; | |
} | |
@Override | |
public String getCompanyName() { | |
return incomeData.getCompany(); | |
} | |
@Override | |
public String getCountryName() { | |
return countries.get(incomeData.getCountryCode()); | |
} | |
@Override | |
public String getName() { | |
return incomeData.getContactLastName()+", "+incomeData.getContactFirstName(); | |
} | |
@Override | |
public String getPhoneNumber() { | |
int phoneCode = incomeData.getCountryPhoneCode(); | |
String phoneFormat = String.format("%010d", incomeData.getPhoneNumber()); | |
String phone = "+"+phoneCode+"("+phoneFormat.substring(0,3)+")"+phoneFormat.substring(3,6)+"-"+phoneFormat.substring(6,8)+ | |
"-"+phoneFormat.substring(8,10); | |
return phone; | |
} | |
} | |
public static interface IncomeData { | |
String getCountryCode(); //example UA | |
String getCompany(); //example JavaRush Ltd. | |
String getContactFirstName(); //example Ivan | |
String getContactLastName(); //example Ivanov | |
int getCountryPhoneCode(); //example 38 | |
int getPhoneNumber(); //example 501234567 | |
} | |
public static interface Customer { | |
String getCompanyName(); //example JavaRush Ltd. | |
String getCountryName(); //example Ukraine | |
} | |
public static interface Contact { | |
String getName(); //example Ivanov, Ivan | |
String getPhoneNumber(); //example +38(050)123-45-67 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment