I tried the solution with german or english labels.
It seems not to be solvable with both alternatives.
package de.codegym.task.task19.task1903;
/*
Mehrere Interfaces adaptieren
*/
import java.util.HashMap;
import java.util.Map;
public class Solution {
public static Map<String, String> countries = new HashMap<>();
static {
// countries.put("FR", "France");
// countries.put("UA", "Ukraine");
// countries.put("US", "United States of America");
countries.put("FR", "Frankreich");
countries.put("UA", "Ukraine");
countries.put("US", "Vereinigte Staaten von Amerika");
}
public static void main(String[] args) {
System.out.println(countries);
}
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 phoneNrString = Long.toString(data.getPhoneNumber());
while (phoneNrString.length() < 10) {
phoneNrString = "0" + phoneNrString;
}
String prefix = phoneNrString.substring(0,3);
String second = phoneNrString.substring(3,6);
String third = phoneNrString.substring(6,8);
String last = phoneNrString.substring(8);
return ("+" + data.getCountryPhoneCode() + "(" + prefix + ")" + second + "-" + third + "-" + last);
}
}
public static interface IncomeData {
String getCountryCode(); // Beispiel: US
String getCompany(); // Beispiel: CodeGym Ltd.
String getContactFirstName(); // Beispiel: John
String getContactLastName(); // Beispiel: Smith
int getCountryPhoneCode(); // Beispiel: 1
int getPhoneNumber(); // Beispiel: 991234567
}
public static interface Customer {
String getCompanyName(); // Beispiel: CodeGym Ltd.
String getCountryName(); // Beispiel: United States
}
public static interface Contact {
String getName(); // Beispiel: Smith, John
String getPhoneNumber(); // Beispiel: +1(099)123-45-67
}
}