Does the format of the returned phone number have to match the sample exactly (with + and () and spaces)?
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 incomeData){
this.data = incomeData;
}
public String getCompanyName() {
return data.getCompany();
}
public String getCountryName() {
String countryCode = data.getCountryCode();
String country = Solution.countries.get(countryCode);
return country;
}
public String getName() {
String firstName = data.getContactFirstName();
String lastName = data.getContactLastName();
return lastName + ", " + firstName;
}
public String getPhoneNumber() {
String pn = String.format("%010d", data.getPhoneNumber());
pn = data.getCountryPhoneCode() + pn;
return pn;
}
}
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: 501234567
}
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: +38(050)123-45-67
}
}