New to Java programming and need help with my program. The program should output
1:919:882:5000
5000
1
882
919
driver program
public class SSProg1
public static void main(String[] args)
{
SSDissector phone = new SSDissector("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));
}
class file
public class SSDissector
{
private String colonSeparated; // Full phone number with colon's
private String countryCode; // Country Code of the phone number only
private int areaCode; // Area code of the phone number only
private int prefix; // Prefix of the phone number only
private int number; // Last four digits of the phone number only
//************************************************** ******************************
public SSDissector(String colonSeparated)
{
this.colonSeparated = colonSeparated;
int index1 = colonSeparated.indexOf(":");
this.countryCode = colonSeparated.substring(index1 - 1, 1);
//System.out.println(countryCode);
int index2 = colonSeparated.indexOf(':');
String areaCode = colonSeparated.substring(index2 + 1, 5);
//System.out.println(areaCode);
//this.prefix = prefix;
int index3 = colonSeparated.lastIndexOf(':');
String prefix = colonSeparated.substring(index3 - 3, 9);
//System.out.println(prefix);
int index4 = colonSeparated.lastIndexOf(':');
String number = colonSeparated.substring(index4 + 1);
//System.out.println(number);
}
//************************************************** ********************************
// This method returns the string colonSeparated
public String getPhoneNumber()
{
return this.colonSeparated;
}// End getPhoneNumber()
//************************************************** ********************************
// This Method returns the corrisponding section of the number
public int getPhoneNumber(int x)
{
if (x==1)
{
int countryCodeInt = Integer.parseInt(countryCode);
return countryCodeInt;
}
if (x==2)
{
return areaCode;
}
if (x==3)
{
return prefix;
}
if (x==4)
{
return number;
}
else
{
return number;
}
}// End getPhoneNumber(int)
}// End MFDissector