I might not understand the requirements correctly but I understand that the phone number must be returned in the following format:
// For example: +1(099)123-45-67
What am I missing?
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<>();
//step 2 : Initialize the countries field in a static block in the Solution
// class using the test data provided in the task.
static {
countries.put("UA", "Ukraine");
countries.put("US", "United States");
countries.put("FR", "France");
}
public static void main(String[] args) {
}
//Step 3:The IncomeDataAdapter class must implement the Customer and Contact interfaces.
public static class IncomeDataAdapter implements Customer, Contact{
//step 4: The IncomeDataAdapter class must have a private IncomeData field called data.
private IncomeData data;
//step 5: The IncomeDataAdapter class must have a constructor with an IncomeData parameter.
public IncomeDataAdapter(IncomeData data) {
this.data = data;
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getCountryName() {
//first get the countryCode and get the value => Country's Name
return countries.get(data.getCountryCode());
}
@Override
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
String phoneNumber = String.valueOf(data.getPhoneNumber());
char[] digits = phoneNumber.toCharArray();
return "+" + data.getCountryPhoneCode() +
"(0" + digits[0] + digits[1] + ")" +
digits[2] + digits[3] + digits[4] + "-" +
digits[5] + digits[6] + "-" +
digits[7] + digits[8];
}
}
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
}
}