Не проходит проверку. Номер телефона вроде корректно возвращает, если я правильно понял.
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;
public IncomeDataAdapter(IncomeData data) {
this.data = data;
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getCountryName() {
return countries.get(data.getCountryCode());
}
@Override
public String getName() {
return String.format("%s, %s", data.getContactLastName(), data.getContactFirstName());
}
@Override
public String getPhoneNumber() {
String zero = "0000000000";
String phone = Integer.toString(data.getPhoneNumber());
String phoneVar = phone.substring(0, phone.length() - 7);
String phoneConst = phone.substring(phone.length() - 7, phone.length());
return String.format("+%s(%s%s)%s-%s-%s", data.getCountryPhoneCode(), zero.substring(0, 3 - phoneVar.length()),phoneVar, phoneConst.substring(0, 3),
phoneConst.substring(3, 5), phoneConst.substring(5, 7));
}
}
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
}
}
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;
public IncomeDataAdapter(IncomeData data) {
this.data = data;
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getCountryName() {
return countries.get(data.getCountryCode());
}
@Override
public String getName() {
return String.format("%s, %s", data.getContactLastName(), data.getContactFirstName());
}
@Override
public String getPhoneNumber() {
String zero = "0000000000";
String phone = Integer.toString(data.getPhoneNumber());
String phoneVar = phone.substring(0, phone.length() - 7);
String phoneConst = phone.substring(phone.length() - 7, phone.length());
return String.format("+%s(%s%s)%s-%s-%s", data.getCountryPhoneCode(), zero.substring(0, 3 - phoneVar.length()),phoneVar, phoneConst.substring(0, 3),
phoneConst.substring(3, 5), phoneConst.substring(5, 7));
}
}
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
}
}