I dont know why task is not getting verified even after getting the correct value from methods.. Can anyone help me in this task ?
package com.codegym.task.task19.task1903;
import java.util.*;
/*
Adapting multiple interfaces
Requirements:
1. The Solution class must have a public static Map<String, String> field called countries.
2. Initialize the countries field in a static block in the Solution class using the test
data provided in the task.
3. The IncomeDataAdapter class must implement the Customer and Contact interfaces.
4. The IncomeDataAdapter class must have a private IncomeData field called data.
5. The IncomeDataAdapter class must have a constructor with an IncomeData parameter.
6. Using the hints in the interfaces' comments, implement the methods of the Customer and
Contact interfaces in the IncomeDataAdapter class.
*/
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 data = new IncomeDataAdapter(new IncomeData(){
public String getCountryCode(){
return "US";
}
public String getCompany(){
return "CodeGym Ltd.";
}
public String getContactFirstName(){
return "John";
} // For example: John
public String getContactLastName(){
return "Smith";
} // For example: Smith
public int getCountryPhoneCode(){
return 1;
} // For example: 1
public int getPhoneNumber(){
return 501234567;
} // For example: 501234567
});
data.getCompanyName();
data.getCountryName();
data.getName();
data.getPhoneNumber();
}
public static class IncomeDataAdapter implements Customer, Contact{
private IncomeData data;
IncomeDataAdapter(IncomeData data){
this.data = data;
}
public String getCompanyName(){
System.out.println(data.getCompany());
return data.getCompany();
}
public String getCountryName(){
String countryCode = data.getCountryCode();
String countryName = Solution.countries.get(countryCode);
System.out.println(countryName);
return countryName;
}
public String getName(){
System.out.println(data.getContactLastName()+", "+data.getContactFirstName());
return data.getContactLastName()+", "+data.getContactFirstName();
}
public String getPhoneNumber(){
//+##(###)###-##-##
String code = Integer.toString(data.getCountryPhoneCode());
System.out.println(code);
String number = Integer.toString(data.getPhoneNumber());
System.out.println(number);
if(number.length() < 10){
while(true){
number = "0"+number;
if(number.length() == 10) break;
}
}
System.out.println(number);
char[] array = new char[15];
array = number.toCharArray();
//+##(###)###-##-##
int i = 0;
ArrayList<Character> list = new ArrayList<Character>();
for(char c : array){
if(i == 0){
list.add('(');
list.add(c);
}else if(i == 3){
list.add(')');
list.add(c);
}else if(i == 6 || i == 8){
list.add('-');
list.add(c);
}else{
list.add(c);
}
i++;
for(Character c1 : list){
System.out.print(c1);
}
System.out.println();
}
String num = "";
for(Character c2 : list){
num = num + c2;
}
System.out.println("+"+code+num);
return "+"+code+num;
}
}
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: 501234567
}
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: +38(050)123-45-67
}
}