Hi,
does anyone know why the last condition is not met.
Error
"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."
At first the number is received via data.getPhoneNumber() and then it is lengthen if required. Within the return the number-format is made, but something seem to be wrong.
Many thanks
Eike
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 getName() {
// TODO Auto-generated method stub
return data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
String number = "" + data.getPhoneNumber();
if(number.length() < 10) {
for(int i = number.length() ; i <10 ; i++) {
number = 0 + number;
}
}
return "+" + data.getCountryPhoneCode() + String.valueOf(number).replaceFirst("(\\d{3})(\\d{3})(\\d{2})(\\d+)", "($1)-$2-$3-$4") ;
}
@Override
public String getCompanyName() {
// TODO Auto-generated method stub
return data.getCompany();
}
@Override
public String getCountryName() {
String countryCode = data.getCountryCode();
String country = Solution.countries.get(countryCode);
return country;
}
}
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
}
}