Hi All,
If I could get maybe a second pair of eyes, it would be greatly appreciated as I don't understand why I can't pass validation. I've checked everything I could think of. The phone number from the tests I did come out ten digits with the write format, but the validator only gives me that as a hint... Help please?
Thanks in advanced!
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) {
IncomeDataAdapter test = new IncomeDataAdapter();
System.out.println(test.getPhoneNumber());
// System.out.println(test.getCountryName());
// */
}
public static class IncomeDataAdapter implements Customer, Contact {
private IncomeData data;
public IncomeDataAdapter() {};
public IncomeDataAdapter(IncomeData data) {
this.data = data;
}
@Override
public String getCountryName() {
return countries.get(data.getCountryCode());
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getName() {
return data.getContactLastName() + ", " + data.getContactFirstName();
}
@Override
public String getPhoneNumber() {
// int phoneNumber = data.getPhoneNumber();
int phoneNumber = 991234567;
StringBuilder str = new StringBuilder();
for(int i = 0; i < 10; i++) {
if(i == 1 || i == 3) {
int number = phoneNumber%10;
phoneNumber = phoneNumber/10;
str.append(number);
str.append("-");
}
else if (i == 0 || i == 2 || i == 4 || i == 5 || i == 7 || i == 8) {
int number = phoneNumber%10;
phoneNumber = phoneNumber/10;
str.append(number);
} else if(i == 6) {
int number = phoneNumber%10;
phoneNumber= phoneNumber/10;
str.append(number);
str.append(")");
} else if(i == 9) {
int number = phoneNumber%10;
phoneNumber= phoneNumber/10;
str.append(number);
str.append("(");
}
}
str.append(1 + "+");
// str.append(data.getCountryPhoneCode());
//str.append("+");
return str.reverse().toString();
}
}
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
}
}