Write a class TelephoneNumber that will hold a telephone number. An object of this class will have attributes .. areaCode—a three-digit integer,exchangeCode—a three-digit integer,number—a four-digit int
and the methods
1.TelephoneNumber(aString)—a constructor that creates and returns a new instance of its class xxx–xxx–xxxx or,if the area code is missing, xxx–xxxx. Throw an exception if the format is not valid Hint 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.)
2 .toString—returns a string in either of the two formats shown previously for the contructor.ae
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,creates an array whose base type is Telephone Number.allow the user to
1
Expert's answer
2012-05-08T09:36:57-0400
/* & * To change this template, choose Tools | Templates & * and open the template in the editor. & */
/** & * & * & */ public class TelephoneNumber { private String areaCode; private String exchangeCode; private String number;
/* & * To change this template, choose Tools | Templates & * and open the template in the editor. & */
Comments
Leave a comment