I've already searched the other topics and couldn't find a proper answer to my case. The error message is:
"The getPhoneNumber() method should return a valid phone number (see the examples), padded with zeros if necessary to get 10 digits. The phone number and its country code should be retrieved using the data field's getPhoneNumber() and getCountryPhoneCode() methods."
I've tried some suggestions that I saw on other help topics, but none of them worked. Actually, I don't really understand where the problem is...
Does anyone have a clue?
Thanks!
package com.codegym.task.task19.task1903;
/*
Adapting multiple interfaces
*/
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static Map<String, String> countries = new HashMap<>();
static {
countries.put("UA", "Ukraine");
countries.put("US", "United States");
countries.put("FR", "France");
}
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 data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
String phoneNumber = "";
//adding zeros to the phone number if it has less then 10 digits
if(data.getPhoneNumber() < 10) {
phoneNumber = String.format("%010d", data.getPhoneNumber());
} else { //if the phone number is already with 10 digits
phoneNumber = String.valueOf(data.getPhoneNumber());
}
return "+" + data.getCountryPhoneCode() + phoneNumber.replaceFirst("(\\d{3})(\\d{3})(\\d{2})(\\d{2})", "($1)$2-$3-$4");
}
}
public static interface IncomeData {
String getCountryCode(); // For example: US
String getCompany(); // For example: CodeGym Ltd.
String getContactFirstName(); // For example: John
String getContactLastName(); // For example: Smith
int getCountryPhoneCode(); // For example: 1
int getPhoneNumber(); // For example: 991234567
}
public static interface Customer {
String getCompanyName(); // For example: CodeGym Ltd.
String getCountryName(); // For example: United States
}
public static interface Contact {
String getName(); // For example: Smith, John
String getPhoneNumber(); // For example: +1(099)123-45-67
}
}