Question: Please dont use import statements. Please write comments (ii) write a method named acceptableNumber(String acceptable) that returns a boolean value: true if the parameter phone

Please dont use import statements. Please write comments

(ii) write a method named acceptableNumber(String acceptable) that returns a boolean value: true if the parameter phone represents an acceptable number, false otherwise. An acceptable number consists of 7 digits, which could optionally be separated either by one space or by one dash "-" character between the first 3 digits and the last 4 digits. Also, a number may optionally have a prefix representing the area code. An area code is a sequence of exactly 3 digits surrounded by parenthesis. There can be at most one space character between the area code (if it exists) and the rest of the phone number.

Examples:

acceptableNumber ("(308) 143-6789") returns true

acceptableNumber ("345-7928") returns true

acceptableNumber ("(2005) 427-452") returns false

acceptableNumber("892 326 1") returns false

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 Programming Questions!