Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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

Students also viewed these Databases questions

Question

Avoid easy conflict-reducing techniques.

Answered: 1 week ago