Here is my code:
/**************************************************************
* RFDissector.Java
*
*
* This program will dissect a phone number and give the output
* for the country code, area code, prefix, and line number.
**************************************************************/
public class RFDissector
{
String [] temp; //String Split
String colonSeparated; //string will hold the phone number
String countryCode; //country code
int areaCode; //area code
int prefix; //prefix
int number; //line number
//mutators
public RFDissector(String colonSeparated)
{
this.colonSeparated = ColonSeparted;
temp = colonSeparated.split(":");
}
public String getPhoneNumber()
{
return colonSeparated;
}
public String getPhoneNumber(1)
{
countryCode=colonSeparated.subString(0,colonSeparated.indexOf(":"));
}
public String getPhoneNumber(2)
{
String AreaCode = colonSeparated.subString(countryCode + 1, colonSeparated.indexOf(":"));
areaCode = Integer.parseInt(AreaCode);
}
public String getPhoneNumber(3)
{
String prefix= colonSeparated.subString(countryCode + 2, colonSeparated.indexOf(":"));
prefix = Integer.parseInt(prefix);
}
public String getPhoneNumber(4)
{
String number = colonSeparated.subString(countryCode + 3, colonSeparated.indexOf(":"));
number = Integer.parseInt(number);
}
}//end public class RFDissector
Here is my driver:
public class RFProg1
{
public static void main (String[] args)
{
RFDissector phone = new RFDissector("1:919:882:5000");
System.out.println(phone.getPhoneNumber());
System.out.println(phone.getPhoneNumber(4));
System.out.println(phone.getPhoneNumber(1));
System.out.println(phone.getPhoneNumber(3));
System.out.println(phone.getPhoneNumber(2));
} // end main
}// end class

New Topic/Question
Reply



MultiQuote



|