Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help writing my Dissector.java file. I have the driver file done alr

ID: 3631262 • Letter: I

Question

I need some help writing my Dissector.java file. I have the driver file done already, but need to implement a program to print the following number to seperate as such....

When using the main method specified above, your output should be:

1:919:882:5000
5000
1
882
919

below is what I got so far.




/*******************************************************************
*HLMDissector.java
*
*Holly McCormick
*
*Breaking up a full phone number program
********************************************************************/

public class HLMDissector {

private String colonSeparated; // Full number
private String countryCode; // country code
private int areaCode; // areacode
private int prefix; // prefix
private int number; // number

// Accessor Methods
public String getColonSeparated() { // method to return the full number (Example value: "1:919:882:5000")
return this.colonseparated;
}
public String getCountryCode() { // method to return the country code only
return this.countrycode;
}
public int getAreaCode() { // method to return the areacode only
return this.areacode;
}
public int getPrefix() { // method to return the prefix only
return this.prefix;
}
public int getNumber() { // method to return the number only
return this.number;
}
}


//Driver Class:
/***********************************************
* HollyMccormickProg1.java
* Holly McCormick
*
* Breaking up a full phone number program
***********************************************/

public static void main(String[] args)

{

YIDissector phone = new YIDissector("1:919:882:5000");

System.out.println(phone.getPhoneNumber()); //full phone number

System.out.println(phone.getPhoneNumber(4)); //line number

System.out.println(phone.getPhoneNumber(1)); //country code

System.out.println(phone.getPhoneNumber(3)); //prefix

System.out.println(phone.getPhoneNumber(2)); //area code

} // end main

Explanation / Answer

please rate -thanks


//Driver Class:
/***********************************************
* HollyMccormickProg1.java
* Holly McCormick
*
* Breaking up a full phone number program
***********************************************/

public class HLMDissector
{
public static void main(String[] args)

{

YIDissector phone = new YIDissector("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));


}
}

----------------------------


/*******************************************************************
*HLMDissector.java
*
*Holly McCormick
*
*Breaking up a full phone number program
********************************************************************/
class YIDissector
{private int country, area, prefix, number;

public YIDissector(String a)
{int loc0,loc1;
loc1=a.indexOf(':');
country=Integer.parseInt(a.substring(0,loc1));
loc0=a.indexOf(':',loc1+1);
area=Integer.parseInt(a.substring(loc1+1,loc0));
loc1=a.indexOf(':',loc0+1);
prefix=Integer.parseInt(a.substring(loc0+1,loc1));
number=Integer.parseInt(a.substring(loc1+1));
}
public String getPhoneNumber()
{String a="",num;
num=Integer.toString(country);
a=a+num;
a=a+':';
num=Integer.toString(area);
a=a+num;
a=a+':';
num=Integer.toString(prefix);
a=a+num;
a=a+':';
num=Integer.toString(number);
a=a+num;
return a;
}

public int getPhoneNumber(int pos)
{
   switch(pos)
    {case 1: return country;
      case 2: return area;
      case 3: return prefix;
      case 4: return number;
      }
   return number;
}
}