Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use java 8 pls 25m left ALL O 2 2. Rest API: Country Codes Given a country name and a phone number, query an API

image
image
image
image
image
use java 8 pls

25m left ALL O 2 2. Rest API: Country Codes Given a country name and a phone number, query an API to get calling codes for the country. Prepend the calling code to the phone number and return the string. If the data array is empty. return -1. If there are multiple calling codes returned, use the one at the highest index. The format of the number should be: + Example: +1 765355443 Given a country name, fetched the information from the API at https://jsonmock.hackerrank.com/api/countrie s?name= Each country in data has the following schema: name - The name of the country (String) capital. The name of the capital city for the country (String) callingCodes. An array of all the calling codes for the country (String Array) The country schema may contain other fields which are not relevant for this question. An example of a country record is as follows: name : Afghanistan , nativeName : , topLevelDomain : [ .af ], alpha2Code : AF , numericCode : 004 , alpha3Code : AFG , currencies : [ AFN ], callingCodes : [ } 93 ], capital : Kabul . If a country is in the system, the returned data array contains exactly 1 result. Otherwise, the data array is empty. ******* m left ALL Function Description Complete the getPhoneNumbers function in the editor below. getPhoneNumbers has the following parameters: string country: the country to query string phoneNumber: the phone number Returns string: the completed phone number or -1 Constraints The country name may contain uppercase and lowercase English letters and (ascii 32) Input Format For Custom Testing Sample Case 9 Sample Input For Custom Testing Afghanistan 656445445 Sample Output +93 656445445 Explanation A call is made to API https://jsonmock.hackerrank.com/api/countrie s?name Afghanistan. The calling codes array contains 1 entry, 93 . Sample Case 1 Sample Case 2 contains 1 entry, 93 . Sample Case 1 Sample Input For Custom Testing Puerto Rico 564593986 Sample Output +1939 564593986 Explanation A call is made to the API to fetch the record for Puerto Rico. The returned callingCodes = [ 1787 , 1939]. Use the higher index code, callingCodes[1]. Sample Case 2 Sample Input For Custom Testing Oceania 987574876 Sample Output -1 Explanation The API call return has an empty data array. 13 14 15 class Result 16 17 V /* 18 PANNENHUNDE 19 20 *The function is expected to return a STRING. * The function accepts following parameters: * 1. STRING country * 2. STRING * API URL: https://jsonmock.hackerrank.com/api/countries?name= */ 27 V public static String getPhoneNumbers (String country, String phoneNumber) { 21 22 23 24 25 26 28 29 30 * Complete the getPhoneNumbers function below. * } 31 32 33 y nih? phoneNumber

Step by Step Solution

3.42 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

To solve this problem we need to follow these steps 1 Make a GET request to the API endpoint ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Electrical Engineering questions

Question

What does non-recourse financing mean?

Answered: 1 week ago

Question

What is aggregate operations planning? What is its purpose?

Answered: 1 week ago