Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 Programming questions