Adapting multiple interfaces

  • 20
  • Locked
Adapt IncomeData to the Customer and Contact interfaces. The adapter class is IncomeDataAdapter. Initialize countries before running the program. Mapping between country codes and country names: UA Ukraine US United States FR France If necessary, pad phone numbers with zeros to get 10 digits long (s
You can't complete this task, because you're not signed in.
Comments (17)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Mike S
Level 26 , Saint Louis, United States
17 February, 20:06
I don't even understand where the database is that these methods are supposed to access information from. The only one is the HashMap of countries and their codes...
Justin Smith
Level 38 , Greenfield, USA, United States
11 October 2021, 19:09
I feel like I need about 20 more tasks like this to understand how to even use adapter classes. I can do the tasks but ask me what this is actually for and I'm like 😶.
Karas Java Developer
9 October 2021, 00:16
Yep it works String.format() - pass the "%010d" as argument and also the method to get the phone. then dot notate this: replaceAll("(\\d{3})(\\d{3})(\\d{2})(\\d{2})", "($1)$2-$3-$4") And do not forget to add the country code with a method and the plus sign. stringFormat replaceAll
Gellert Varga
Level 23 , Szekesfehervar, Hungary
16 September 2021, 10:03
The example given should be clarified. In the incomeData interface, one of the data fields would be completely accurate if :
int getCountryPhoneCode(); // For example: 1, or 36, or 238, etc.
// So the country code can be larger than single digit!
My code failed several times because the code expected the country code to always be a single digit, as the example originally shows. In my first code this would have resulted in the StringBuilder insert() method putting the brackets and hyphens in the wrong place for country codes of different lengths.
matemate123
Level 32 , Kraków, Poland
27 January, 21:58
I agree with you. Sometimes conditions are not clear. If that is for purpose, my bad.
Ryan Vibbert
Level 23 , Columbus, United States
2 June 2021, 19:41
I'm getting back a validation error in regards to my getName implementation even though I have it setup correctly. Someone may want to review why this validation error is occurring. I even downloaded the solution to check my error and it was the same code.
Jurij Thmsn
Level 29 , Flensburg, Germany
17 April 2021, 13:56
Main difficulty here is the String formatting. hint - padding int with zeroes:
String.format("%03d", 7); //output: 007
did the rest of the formatting with substrings.
26 February 2021, 20:31
CodeGym, please start providing expected output. I had to go to help section to check what the correct phone number format is. This task is currently rated at 1 star (probably because it cannot go below). @All - it is +1(099)123-45-67
Alex Vypirailenko Java Developer at Toshiba Global Comme
27 February 2021, 17:28
Mateusz
Level 29 , Poland
16 September 2020, 10:01
If you have problems with phone number formatting, StringBuffer or StringBuilder come in handy :)
Nastya
Level 19 , Moscow, Russia
13 August 2020, 17:57
Maybe it can help Use String.format() "%010d" replaceAll("(\\d{3})(\\d{3})(\\d{2})(\\d{2})", "($1)$2-$3-$4")
Karas Java Developer
9 October 2021, 00:12
https://www.javatpoint.com/java-string-format https://www.javatpoint.com/java-string-replaceall
Felix
Level 19
22 April 2020, 22:48
"If necessary, pad phone numbers with zeros to get 10 digits long (see the examples)." Which examples?
Henrique
Level 41 , São Paulo, Brazil
29 June 2020, 14:49
I think it's referring to line 45. The given number is 9 digits long ("991234567", line 33), and it's padded with a "0" to make it 10 digits long on line 45 (after the country phone code).