代写 Scenario

Scenario
When a user calls a phone, they can dial a number in their own country by using a national number, or dial a number in any country by using an international number.
National numbers begin with a national trunk prefix, e.g. Ò02079560056Ó. National trunk prefixes can be any length (including zero), and vary by country.
International numbers begin with Ò+Ó followed by the calling code of the country they wish to call, e.g. Ò+442079560056Ó (in this case, Ò44Ó is the country calling code). Calling codes are between 1 and 4 digits long, inclusive, and never begin with a Ò0Ó.
National and international numbers can be converted between each other by changing the prefix and leaving the remaining digits the same.
Thus, if the UK calling code is Ò44Ó and the national trunk prefix is Ò0Ó, the number Ò+442079460056Ó can be reached from another UK number by dialling Ò02079460056Ó.
Phone numbers are considered to be in the same country if and only if their country calling codes are the same.
Task
Write a class that, when given a dialled phone number (national or international) and the userÕs international phone number, returns the dialled phone number in international format.
The constructor should accept a mapping of country codes (e.g. ÒGBÓ, ÒUSÓ) to the corresponding country calling codes (e.g. 44, 1), and a mapping of country codes to the corresponding national trunk prefixes (e.g. Ò0Ó, Ò1Ó).
Expected format:
public class NumberParser {
public NumberParser(Map callingCodes, Map prefixes) {
// TODO }
public String parse(String dialledNumber, String userNumber) {
// TODO }
}
Example usage:
Map countryCodes = new HashMap<>();
Map prefixes = new HashMap<>();
countryCodes.put(“GB”, 44); prefixes.put(“GB”, “0”);
countryCodes.put(“US”, 1); prefixes.put(“US”, “1”);
NumberParser parser = new NumberParser(countryCodes);
assertEquals(“+442079460056”, parser.parse(“02079460056”, “+441614960148”));
assertEquals(“+442079460056”, parser.parse(“+442079460056”, “+441614960148”));
assertEquals(“+442079460056”, parser.parse(“02079460056”, “+441614960148”));
Note:
This is a huge simplification of the real telephony system, and makes a lot of invalid assumptions, but will do for the purpose of this exercise.