-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
151 lines (105 loc) · 4.85 KB
/
Solution.java
File metadata and controls
151 lines (105 loc) · 4.85 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
//I know that, when I come to you, I will come in the fullness of the blessing of the Good News of Christ. (Romans 15:29)
package com.javarush.task.task19.task1903;
/*
Адаптация нескольких интерфейсов
*/
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 IncomeDataAdapter implements Customer, Contact {
private IncomeData data;
public IncomeDataAdapter(IncomeData incomeData) {
this.data = incomeData;
}
@Override
public String getCompanyName() {
return data.getCompany();
}
@Override
public String getCountryName() {
return countries.get(data.getCountryCode());
}
@Override
public String getName() {
return String.format("%s, %s", data.getContactLastName(), data.getContactFirstName());
}
@Override
public String getPhoneNumber() {
String phone = String.format("%010d", data.getPhoneNumber());
String result = "+" + data.getCountryPhoneCode() + "(" + phone.substring(0,3) + ")" +
phone.substring(3,6) + "-" + phone.substring(6,8) + "-" + phone.substring(8);
return result ;
}
}
public static interface IncomeData {
String getCountryCode(); //example UA
String getCompany(); //example JavaRush Ltd.
String getContactFirstName(); //example Ivan
String getContactLastName(); //example Ivanov
int getCountryPhoneCode(); //example 38
int getPhoneNumber(); //example 501234567
}
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
}
}
/*
Адаптация нескольких интерфейсов
Адаптируй IncomeData к Customer и Contact.
Классом-адаптером является IncomeDataAdapter.
Инициализируйте countries перед началом выполнения программы. Соответствие кода страны и названия:
UA Ukraine
RU Russia
CA Canada
Дополнить телефонный номер нулями до 10 цифр при необходимости (смотри примеры).
Обратите внимание на формат вывода фамилии и имени человека.
Требования:
1. Класс Solution должен содержать public static поле countries типа Map.
2. В статическом блоке класса Solution инициализируй поле countries тестовыми данными согласно заданию.
3. Класс IncomeDataAdapter должен реализовывать интерфейсы Customer и Contact.
4. Класс IncomeDataAdapter должен содержать приватное поле data типа IncomeData.
5. Класс IncomeDataAdapter должен содержать конструктор с параметром IncomeData.
6. В классе IncomeDataAdapter реализуй методы интерфейсов Customer и Contact используя подсказки в виде комментариев в интерфейсах.
package com.javarush.task.task19.task1903;
*
Адаптация нескольких интерфейсов
*
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 IncomeDataAdapter {
}
public static interface IncomeData {
String getCountryCode(); //example UA
String getCompany(); //example JavaRush Ltd.
String getContactFirstName(); //example Ivan
String getContactLastName(); //example Ivanov
int getCountryPhoneCode(); //example 38
int getPhoneNumber(); //example 501234567
}
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
}
}
*/