In: Computer Science
In the programming language java: Write a class encapsulating the concept of a telephone number, assuming a telephone number has only a single attribute: aString representing the telephone number. Include a constructor, the accessor and mutator, and methods 'toString' and 'equals'. Also include methods returning the AREA CODE (the first three digits/characters of the phone number; if there are fewer than three characters in the phone number of if the first three characters are not digits, then this method should return "unknown area code"). Write a client class to test all the methods in your class. Look up the getClass method in the Object class and the getName method in the Class class and use them in your client.
(The last time I posted it the answer was in regard to bills not area code, please make sure the answer is accurate)
class telephone_number
{
String aString;
telephone_number()
{
aString="00000";
}
void toString(int n)
{
aString= String.valueOf(n);
}
String equals()
{
String str;
if(aString.length()<3)
{
str="Wrong
Number";
}
else
{
str=
aString.substring(0,3);
}
return str;
}
}
class get_substring
{
public static void main(String args[])
{
telephone_number o=new
telephone_number();
o.toString(123456);
String s=o.equals();
System.out.println("Area Code is
" + s);
}
}