I've tested my getDialString method for the phone numbers from examples and it shows correct output, but it doesn't pass the verification. The recommendation from mentor is: " The getDialString() method should return a String containing "callto://+" and a phone number with all characters removed except digits (see the examples). The phone number must be retrieved using the contact field's getPhoneNumber() method. ". Is there something wrong in my code?
package com.codegym.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Reinforce the adapter
*/
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 DataAdapter implements RowItem{
private Customer customer;
private Contact contact;
public DataAdapter(Customer customer, Contact contact) {
this.customer = customer;
this.contact = contact;
}
public String getCountryCode() {
String countryCode = "";
for (Map.Entry<String, String> pair : countries.entrySet()) {
if (pair.getValue().equals(customer.getCountryName())) {
countryCode = pair.getKey();
}
}
return countryCode;
}
public String getCompany() {
return customer.getCompanyName();
}
public String getContactFirstName() {
String firstName = contact.getName();
return firstName.substring(firstName.lastIndexOf(" ")+ 1);
}
public String getContactLastName() {
String lastName = contact.getName();
return lastName.substring(0, lastName.indexOf(","));
}
public String getDialString() {
StringBuilder sb = new StringBuilder(contact.getPhoneNumber());
sb.deleteCharAt(sb.indexOf("+"));
sb.deleteCharAt(sb.indexOf("("));
sb.deleteCharAt(sb.indexOf(")"));
sb.deleteCharAt(sb.indexOf("-"));
return "callto://+" + sb.toString();
}
}
public static interface RowItem {
String getCountryCode(); // For example: US
String getCompany(); // For example: CodeGym Ltd.
String getContactFirstName(); // For example: John
String getContactLastName(); // For example: Peterson
String getDialString(); // For example: callto://+11112223333
}
public static interface Customer {
String getCompanyName(); // For example: CodeGym Ltd.
String getCountryName(); // For example: United States
}
public static interface Contact {
String getName(); // For example: Peterson, John
String getPhoneNumber(); // For example: +1(111)222-3333, +3(805)0123-4567, +380(50)123-4567, etc.
}
}