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