So, If I instead of doing multiple "String.format" as shown in correct code, I do it once for "data.getPhoneNumber()", save result in variable, then split phone number from that variable in parts as done in correct code, Validation of my code didn't pass? Really?
package com.codegym.task.task19.task1903;
/*
Adapting multiple interfaces
*/
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
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 Contact, Customer{
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 String.format("%s, %s",data.getContactLastName(), data.getContactFirstName());
}
@Override
public String getPhoneNumber() {
String phoneNum = String.format("%010%d",data.getPhoneNumber());
return String.format("+%d(%s)%s-%s-%s",
data.getCountryPhoneCode(),
phoneNum.substring(0,3),
phoneNum.substring(3,6),
phoneNum.substring(6,8),
phoneNum.substring(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
}
}