В классе IncomeDataAdapter реализуй методы интерфейсов Customer и Contact используя подсказки в виде комментариев в интерфейсах.
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 Customer, Contact {
private IncomeData data;
IncomeDataAdapter (IncomeData data){
this.data = data;
}
public String getCompanyName(){
return this.data.getCompany();
}
public String getCountryName(){
String s = "";
for (Map.Entry<String,String> entry : countries.entrySet()){
if (entry.getKey().equals(this.data.getCountryCode())){
s = entry.getValue();
}
}
return s;
}
public String getName(){
return this.data.getContactLastName() + ", " + this.data.getContactFirstName();
}
public String getPhoneNumber(){
String s = String.format("%010d", this.data.getPhoneNumber());
if (s.length()<10){ // 71112233
while (s.length()!=10){
s = "0" + s;
}
}
String i = s.substring(0,3);
String i2 = s.substring(3,6);
String i3 = s.substring(6,8);
String i4 = s.substring(8);
return ("+" + this.data.getCountryCode() + "(" + i + ")" + i2 + "-"+ i3 + "-"+ i4);
}
}
public 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 example1: 501234567, For example2: 71112233
}
public interface Customer {
String getCompanyName(); //For example: JavaRush Ltd.
String getCountryName(); //For example: Ukraine
}
public interface Contact {
String getName(); //For example: Ivanov, Ivan
String getPhoneNumber(); //For example1: +38(050)123-45-67, For example2: +38(007)111-22-33
}
}