Валидатор выдаёт следующие:"Метод getPhoneNumber() должен вернуть валидный телефонный номер (смотри примеры), дополненный нулями до 10 цифр при необходимости. Телефонный код страны нужно взять из getCountryPhoneCode(), а сам номер из getPhoneNumber() объекта data."
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("RU","Russia");
countries.put("CA","Canada");
countries.put("UA","Ukraine");
}
public static void main(String[] args) {
}
public static class IncomeDataAdapter implements Customer,Contact {
private IncomeData data;
public IncomeDataAdapter(IncomeData incomeData) {
this.data = incomeData;
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getCountryName() {
String country_code = data.getCountryCode();
return countries.get(country_code);
}
@Override
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
int Phone_number = data.getPhoneNumber();
int last_part = Phone_number % 100;
Phone_number = Phone_number / 100;
int third_part = Phone_number % 100;
Phone_number = Phone_number / 100;
int second_part = Phone_number % 1000;
Phone_number = Phone_number / 1000;
if(Phone_number < 100)
{
return "+" + data.getCountryPhoneCode() + "(0" + Phone_number + ")" + second_part + "-" + third_part + "-" +last_part;
}
else
{
return "+" + data.getCountryPhoneCode() + "(" + Phone_number + ")" + second_part + "-" + third_part + "-" +last_part;
}
}
}
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
}
}