Hello guys,
I don't understand why my solution is not approved. I tested it with several phone numbers and it delivered the numbers in the right format? Thanks for your help :)
package de.codegym.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Adapter stärken
*/
public class Solution {
public static Map<String,String> countries = new HashMap<>();
static {
countries.put("UA", "Ukraine");
countries.put("US", "Vereinigte Staaten von Amerika");
countries.put("FR", "Frankreich");
}
public static void main(String[] args) {
}
public static class DataAdapter implements RowItem {
private Customer customer;
private Contact contact;
public DataAdapter(Customer customer, Contact contact) {
this.customer = customer;
this.contact = contact;
}
@Override
public String getCountryCode() {
StringBuffer countrycode = new StringBuffer();
String name = customer.getCountryName();
for (Map.Entry<String, String> entry : countries.entrySet()){
if (entry.getValue().equals(name)){
countrycode.replace(0,3, entry.getKey());
}
}
return countrycode.toString();
}
@Override
public String getCompany() {
return customer.getCompanyName();
}
@Override
public String getContactFirstName() {
return contact.getName().substring(contact.getName().indexOf(",")+2);
}
@Override
public String getContactLastName() {
return contact.getName().substring(0, contact.getName().indexOf(","));
}
@Override
public String getDialString() {
String diaL = contact.getPhoneNumber();
StringBuffer dial = new StringBuffer();
int o = diaL.indexOf("(");
dial.append(diaL.substring(0, o));
int z = diaL.indexOf(")");
dial.append(diaL.substring(o+1, z));
int s = diaL.indexOf("-");
dial.append(diaL.substring(z+1,s));
dial.append(diaL.substring(s+1));
dial.insert(0,"anrufen://");
return dial.toString();
}
}
public static interface RowItem {
String getCountryCode(); // Beispiel: US
String getCompany(); // Beispiel: CodeGym Ltd.
String getContactFirstName(); // Beispiel: John
String getContactLastName(); // Beispiel: Peterson
String getDialString(); // Beispiel: callto://+11112223333
}
public static interface Customer {
String getCompanyName(); // Beispiel: CodeGym Ltd.
String getCountryName(); // Beispiel: United States
}
public static interface Contact {
String getName(); // Beispiel: Peterson, John
String getPhoneNumber(); // Beispiel: +1(111)222-3333, +3(805)0123-4567, +380(50)123-4567 usw.
}
}