Write a class TelephoneNumber that will hold a telephone number. An object of this class will have

Question:

Write a class TelephoneNumber that will hold a telephone number. An object of this class will have the attributes

  • areaCode—a three-digit integer
  • exchangeCode—a three-digit integer
  • number—a four-digit integer

and the methods

  • TelephoneNumber(aString)—a constructor that creates and returns a new instance of its class, given a string in the form xxx–xxx–xxxx or, if the area code is missing, xxx–xxxx. Throw an exception if the format is not valid. (Hint: To simplify the constructor, you can replace each hyphen in the telephone number with a blank. To accept a telephone number containing hyphens, you could process the string one character at a time or learn how to use Scanner to read words separated by a character—such as a hyphen—other than whitespace.) 
  • toString—returns a string in either of the two formats shown previously for the constructor.

Using a text editor, create a text file of several telephone numbers, using the two formats described previously. Write a program that reads this file, displays the data on the screen, and creates an array whose base type is TelephoneNumber. Allow the user to either add or delete one telephone number. Write the modified data on the text file, replacing its original contents. Then read and display the numbers in the modified file.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: