Протестировал, номер нормально выдает. Я даже уже вообразить не могу , что может быть не так. Прошу, помогите!
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;
}
public String getCompanyName() {
return data.getCompany();
}
public String getCountryName() {
String countryName = "";
for (Map.Entry<String, String> entry : countries.entrySet()) {
if (data.getCountryCode() == entry.getKey()){
countryName = entry.getValue();
}
}
return countryName;
}
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
public String getPhoneNumber() {
String countryCode = String.valueOf(data.getCountryCode());
String countryPhoneNumber = String.valueOf(data.getPhoneNumber());
countryPhoneNumber = String.format("%10s", countryPhoneNumber);
String fullNumber = countryPhoneNumber.replaceAll(" ", "0");
String result = "+" + countryCode + "(" + fullNumber.substring(0,3) +
")" + fullNumber.substring(3,6) + "-" +
fullNumber.substring(6,8) + "-" + fullNumber.substring(8);
return result;
}
}
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
}
}