The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 3 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Problem 2
Write a PhoneNumber class that gets initialized with a 10-digit phone number. In the call PhoneNumber.new(ph), the input phtake any of these possible formats:
Â
• a 10-digit integer
Â
• a string of 10 digits
Â
• (ddd) ddd-dddd where d is any digit [parenthesis format]
Â
• ddd-ddd-dddd where d is any digit [hyphen format]
Â
Wherever whitespace appears in a string format, we can have a string of zero or more whitespace characters (including before and after the string as a whole). A PhoneNumber object responds to the to_s message which returns the number as a string in parenthesis format, and the area_code, prefix, and root messages which return the parts of the number in string format, as illustrated
Â
here:
Â
a = PhoneNumber.new(1234567890)
Â
puts a # (123) 456-7890 puts a.area_code # 123 puts a.prefix # 456
Â
puts a.root # 7890
Â
puts PhoneNumber.new(' 7778889999 ') # (777) 888-9999 puts PhoneNumber.new(' (555)444-3333') # (555) 444-3333
Â
PhoneNumber.new('1234')
Â
# ArgumentError: Improper phone number syntax
Â
PhoneNumber.new('(12) 333-4444')
Â
# ArgumentError: Improper phone number syntax
Â
PhoneNumber.new('123- 456- 7890')
# ArgumentError: Improper phone number syntax
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll