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(){
for (Map.Entry<String, String> pair : countries.entrySet()){
if (customer.getCountryName() == pair.getValue()){
return pair.getKey();
}
}
return null;
}
public String getCompany(){
return customer.getCompanyName();
}
public String getContactFirstName(){
return contact.getName().substring(contact.getName().indexOf(", ")+1);
}
public String getContactLastName(){
String[] name = contact.getName().split(",");
return name[0];
}
public String getDialString(){
char[] array = contact.getPhoneNumber().toCharArray();
String number = "+";
for (char c :array){
if (c>'0' && c<'9') number += c;
}
return number;
}
}
getContactFirstName() 方法必须返回包含名字的 String(请参见示例)。应使用 contact 字段的 getName() 方法检索名字和姓氏。
为什么通过不了?
求帮助。package zh.codegym.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
巩固适配器
*/
public class Solution {
public static Map<String,String> countries = new HashMap<>();
static {
countries.put("UA", "乌克兰");
countries.put("US", "美国");
countries.put("FR", "法国");
}
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(){
for (Map.Entry<String, String> pair : countries.entrySet()){
if (customer.getCountryName() == pair.getValue()){
return pair.getKey();
}
}
return null;
}
public String getCompany(){
return customer.getCompanyName();
}
public String getContactFirstName(){
return contact.getName().substring(contact.getName().indexOf(", ")+1);
}
public String getContactLastName(){
String[] name = contact.getName().split(",");
return name[0];
}
public String getDialString(){
char[] array = contact.getPhoneNumber().toCharArray();
String number = "+";
for (char c :array){
if (c>'0' && c<'9') number += c;
}
return number;
}
}
public static interface RowItem {
String getCountryCode(); // 例如:US
String getCompany(); // 例如:CodeGym Ltd.
String getContactFirstName(); // 例如:约翰
String getContactLastName(); // 例如:彼得森
String getDialString(); // 例如:拨号://+11112223333
}
public static interface Customer {
String getCompanyName(); // 例如:CodeGym Ltd.
String getCountryName(); // 例如:美国
}
public static interface Contact {
String getName(); // 例如:彼得森,约翰
String getPhoneNumber(); // 例如:+1(111)222-3333,+3(805)0123-4567,+380(50)123-4567 等
}
}