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

  Program to fill 0s and 1s into tictactoe board

Write a program which randomly fills in 0s and 1s into TicTacToe board, prints board.

  Design application that reads arbitary number of integers

Design and implement an application that reads an arbitary number of integers that are in the range of 0 to 50 inclusive and counts how many occurences of each are entered.

  On a 3 x 4 chessboard there are 3 black knights (b b b)

On a 3 x 4 chessboard there are 3 black knights (B B B) and 3 white knights (W W W). Exchange knights in the minimum number of turns (hint: use graph representation).

  Write a little man program that adds a column of input value

Write a Little Man program that adds a column of input values and produces the sum as output. An input value of zero will indicate the last value in the input stream of input values.

  Explaining object hierarchy in object-oriented programming

Study the concept of inheritance and the object hierarchy in object-oriented programming, and write a paper comparing these concepts with the concept of inheritence.

  Program to display words in a list box sorted by number

Write a program to display the words in a list box sorted by the number of different vowels(a,e,i,o,u) in the word.

  Explain programming language is machine independent

Explain what does it mean to say that programming language is machine independent? What do you mean by operator precedence? Depending on operator precedence, what values could be related with expression 6 + 2 * 3?

  Implement the calculator using stacks and queues

You will implement the calculator using stacks and queues. Your calculator should support following operators: Parenthesis. The input will be given in form of infix expressions, e.g. ( 2 + 3 ) * 5.

  Write script in fedora to automate complex system task

Write a script in fedora 10 that will automate a complex system task. The task I have chose is one that will determine the processes that are consuming system resources.

  Provide a graphical view of the planets and bases

Intergalactic Navigation. Provide a graphical view of the planets and bases, and meteorite fields and display the requested path from start to destination.

  Explain inheritance structures of galaga

Write a 3-page paper about inheritance structures of Galaga. Recognize the parent and child classes and describe what each class has for events and data.

  Recursive method to replace all occurrences of character

Write down the program which uses the recursive method to replace all occurrences of character with another character in given sentence.

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