Проверил в Eclipse, телефон выводит в правильном формате. 2-ю часть дополняет до 10 цифр.
Что может быть не так?
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 data.getCompany();
}
public String getCountryName() {
return countries.get(data.getCountryCode());
}
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
public String getPhoneNumber() {
String pth1 = "+" + data.getCountryPhoneCode() + "(";
String pth2 = "" + data.getPhoneNumber();
if (pth2.length() < 10) { for (int i=0; i <= (10 - pth2.length()); i++) pth2 = "0" + pth2; }
return (pth1 + pth2.substring(0,3) + ")" + pth2.substring(3, 6)
+ "-" + pth2.substring(6, 8) + "-" + pth2.substring(8, 10));
}
}
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
}
}
ХРЕНЬ, извиняюсь конструкцию пошел вынужденно, т.к. вот эта НЕ РАБОТАЕТ pth2 = "0".repeat(10 - pth2.length()) + pth2; Хотя в чате мне написали, что Core примеры проверяются на 11 версии Java.