-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
159 lines (119 loc) · 5.04 KB
/
Solution.java
File metadata and controls
159 lines (119 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//that I may be delivered from those who are disobedient in Judea, and that my service which I have for Jerusalem may be acceptable to the saints (Romans 15:31)
package com.javarush.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
/*
Закрепляем адаптер
*/
public class Solution {
public static Map<String,String> countries = new HashMap<String,String>();
static{
countries.put("UA", "Ukraine");
countries.put("RU", "Russia");
countries.put("CA", "Canada");
}
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 getCompany()
{
return customer.getCompanyName();
}
@Override
public String getContactFirstName()
{
return contact.getName().split(", ")[1];
}
@Override
public String getContactLastName()
{
return contact.getName().split(", ")[0];
}
@Override
public String getCountryCode()
{
String s = "";
for (Map.Entry<String, String> pair : countries.entrySet()){
if (pair.getValue().equals(customer.getCountryName())) s = pair.getKey();
}
return s;
}
@Override
public String getDialString()
{
String phone = "callto://" + contact.getPhoneNumber().replaceAll("[()-]","");
return phone;
}
}
public static interface RowItem {
String getCountryCode(); //example UA
String getCompany(); //example JavaRush Ltd.
String getContactFirstName(); //example Ivan
String getContactLastName(); //example Ivanov
String getDialString(); //example callto://+380501234567
}
public static interface Customer {
String getCompanyName(); //example JavaRush Ltd.
String getCountryName(); //example Ukraine
}
public static interface Contact {
String getName(); //example Ivanov, Ivan
String getPhoneNumber(); //example +38(050)123-45-67
}
}
/*
Закрепляем адаптер
Адаптировать Customer и Contact к RowItem.
Классом-адаптером является DataAdapter.
Инициализируйте countries перед началом выполнения программы. Соответствие кода страны и названия:
UA Ukraine
RU Russia
CA Canada
Требования:
1. Класс Solution должен содержать public static поле countries типа Map.
2. В статическом блоке класса Solution инициализируй поле countries тестовыми данными согласно заданию.
3. Класс Solution должен содержать интерфейс RowItem.
4. Класс Solution должен содержать интерфейс Contact.
5. Класс Solution должен содержать интерфейс Customer.
6. Класс DataAdapter должен реализовывать интерфейс RowItem.
7. Класс DataAdapter должен содержать два приватных поля: customer типа Customer и contact Contact.
8. Класс DataAdapter должен содержать конструктор с параметрами (Customer customer, Contact contact), который инициализирует поля contact и customer.
9. В классе DataAdapter реализуй методы интерфейса RowItem используя подсказки в виде комментариев в интерфейсах.
package com.javarush.task.task19.task1905;
import java.util.HashMap;
import java.util.Map;
*
Закрепляем адаптер
*
public class Solution {
public static Map<String,String> countries = new HashMap<String,String>();
public static void main(String[] args) {
}
public static class DataAdapter {
public DataAdapter(Customer customer, Contact contact) {
}
}
public static interface RowItem {
String getCountryCode(); //example UA
String getCompany(); //example JavaRush Ltd.
String getContactFirstName(); //example Ivan
String getContactLastName(); //example Ivanov
String getDialString(); //example callto://+380501234567
}
public static interface Customer {
String getCompanyName(); //example JavaRush Ltd.
String getCountryName(); //example Ukraine
}
public static interface Contact {
String getName(); //example Ivanov, Ivan
String getPhoneNumber(); //example +38(050)123-45-67
}
}
*/