Question: Problem 2: Create a class PhoneNumberChecker that checks the validity of a given phone number using Regular Expressions. Three countries are supported: Morocco, Spain and

Problem 2:

Create a class PhoneNumberChecker that checks the validity of a given phone number using Regular Expressions. Three countries are supported: Morocco, Spain and England.

Define the following methods:

- validateNumber()

o first asks the user to input the country to which the phone number belongs (remember only three countries are supported). In case on an invalid country, the message This country is not supported by our Phone Number Checker! shall be displayed and the user shall be asked if he/she would like to retry again, if yes, the whole process will be repeated, if not, the program will exit with a Goodbye message.

o Then asks the user to input the phone number and invokes the appropriate validation method (see below). If the validation method returns false, the message (e.g. You have typed an invalid Spanish is displayed. Otherwise, it displays (e.g. This is a valid Moroccan phone number : 00212-6-45456567).

Note: In the following, a phone number in the appropriate format with no hyphens (-) is also valid. Please consider this in the RegEX, as well.

- validateMorrocan() that checks if the String passed as an argument is a valid Moroccan phone number* or not using RegEx. This function is static and returns a Boolean. * The phone number should have the following format: +212-5/6/7-xxxx-xx-xx or 00212-5/6/7-xx-xx-xx-xx

- validateSpanish() that checks if the String passed as an argument is a valid Spanish phone number* or not using RegEx. This function is static and returns a Boolean. * The phone number should have the following format: +34-9xx-xxx-xxx or 0034-9xx-xxx-xxx

- validateEnglish() that checks if the String passed as an argument is a valid British phone number* or not using RegEx. This function is static and returns a Boolean. * The phone number should have the following format: +44-20-xxxxxxxx or 0044-20-xxxx-xxxx

- Main method to test the validity of a given phone number.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!