Write a phonenumber class

Assignment Help Programming Languages
Reference no: EM13324576

Write a PhoneNumber class that gets initialized with a 10-digit phone number. In the call PhoneNumber.new(ph), the input ph take 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

Reference no: EM13324576

Questions Cloud

Calculate the new volume of the gas : An ideal gas occupies a volume of 2.85 m3 at STP. The pressure of the gas in increased to 3.71 atm. Calculate the new volume of the gas
What impact did early white immigrants into tennessee : What impact did early white "immigrants" into Tennessee have on the imperial wars in North America prior to and during the American War of Independence?
Calculate the loss : Marge's auto, which is used for business purposes only, is totally destroyed by a fire. The fair market value of the auto was $8,000 at the time of the fire and the adjusted basis was $10,000. Calculate the loss, and determine whether it is a ..
Stock corporation-sole proprietorship-general partnership : In addition to the “stock corporation” define and describe two of the five following business entities. Sole Proprietorship, General Partnership, Limited Liability Company, and Limited Liability Partnership.
Write a phonenumber class : Write a PhoneNumber class that gets initialized with a 10-digit phone number. In the call PhoneNumber.new(ph), the input ph take any of these possible formats:
The titration was performed to standardize an edta solution : A titration was performed to standardize an EDTA solution. use the following data to calculate the molarity of the EDTA solution. A 50.00 mL aliquot of a standard solution containing 0.025000 M Ca^2+ required 39.92 mL of EDTA to reach a distinct b..
What is the new volume of the gas after it is heated : 4.3 moles of Hydrogen gas initially at Standard Temperature and Pressure. The gas is heated to a temperature of 49°C while being kept at constant pressure. What is the new volume of the gas after it is heated
How she should treat the gain on the sale of the stock : During the year Johnson Co. repurchased 100 shares of its common stock and subsequently resold those shares at an amount that was $7.00 per share greater than the price paid for the shares. Tell the controller of Johnson Co. how she should trea..
Develop recommendations and conclusions : Develop recommendations and conclusions and state them and their rationale. Using and building on the previous information (provided by you) to answer the above from multiple sources and present that data in one to two pages (12-point font, do..

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd