Skip to content

Instantly share code, notes, and snippets.

@0x000000AC
Created January 20, 2013 21:49
Show Gist options
  • Save 0x000000AC/4582013 to your computer and use it in GitHub Desktop.
Save 0x000000AC/4582013 to your computer and use it in GitHub Desktop.
/***********************************************************************
* Title: ACDissector.java
* Description:
* Stores the phone number as a colon separated string of numbers
* and as four separate pieces:
* - colonSeparated "1:919:882:5000"
* - countryCode - stored as a String could hold 001
* - areaCode, prefix, number - stored as int
*
* Constructor:
* ACDissector recieves one parameter, a colon-separated string
* no error checking required. Initializes the instance variables with
* appropriate values. Must use String methods to extract individual sections
* as strings and use parseInt to convert strings into int's
*
* Company: Park University
* Author: Aaron P. Clark
* Email: aaron.clark@park.edu
* Date: 1/19/2013
* Last Change: 1/19/2013
***********************************************************************/
public class ACDissector
{
// Instance variables
private String colonSeparated; // – a colon separated String. Example value: "1:919:882:5000"
private String countryCode; // – stored as a String as it could hold 001
private int areaCode;
private int prefix;
private int number; // - number – stored as int variables
//*******************************************************************
// Primary Constructor. Takes string from driver and initializes appropriate section variables.
public ACDissector(String a)
{
this.colonSeparated = a;
this.number = Integer.parseInt(colonSeparated.substring(10));
this.prefix = Integer.parseInt(colonSeparated.substring(6, 9));
this.areaCode = Integer.parseInt(colonSeparated.substring(2, 5));
// this.countryCode = String.valueOf(colonSeparated.substring(0,1));
} // end constructor
//*******************************************************************
// getPhoneNumber accessor method with no input arguments. Returns input from
// the instantiated object in the driver.
public String getPhoneNumber()
{
return this.colonSeparated;
} // end getPhoneNumber(no arguments)
//*******************************************************************
// get PhoneNumber accessor method with integer argument
// Receives 1, 2, 3 or 4 and returns the section that's at that position
public int getPhoneNumber(int b)
{
if(b==4)
{
return number;
}
else if(b==1)
{
return countryCode;
}
else if(b==3)
{
return prefix;
}
else
{
return areaCode;
}
} // end getPhoneNumber(int arguments)
} // end ACDissector class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment