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

How do I write this program? Directions Points The file must be called <YourName

ID: 3626720 • Letter: H

Question

How do I write this program?



Directions
Points

The file must be called <YourNameProg1.java> (driver program)
<YourInitialsDissector.java> (Dissector class file)

Example:
KenDeweyProg1.java (driver program)
KDDissector.java (dissects the phone number into sections)

Ensure you include ALL files required to make your program compile and run.
I would like to see your .java files only.

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.
5%

Style Requirements

Refer to the Java Coding Style Document in Doc Sharing.
Comments are required for all files including the driver.
10%

Overall Requirements

Every phone number is broken up into sections as shown below:



Country Code
Area Code
Prefix
Line Number

1
919
882
5000




Write a program to separate out a phone number when it is given with colon’s separating the sections.


YourNameProg1.java

Your driver class should contain the following main method: (add comments)

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));

} // end main
10%

YourInitialsDissector.java

Implement a YourInitialsDissector.java class that stores the phone number as a colon separated string of numbers and as four separate pieces described below.



You must implement all of the following:



Instance variables: (10%)

colonSeparated – a colon separated String. Example value: "1:919:882:5000"

countryCode – stored as a String as it could hold 001

areaCode, prefix, number – stored as int variables



Constructor: (30%)

This constructor receives one parameter, a colon-separated string. You may assume that the parameter’s value is valid (i.e., no error checking required). The constructor initializes the instance variables with appropriate values. There are many ways to solve the problem of extracting the sections from the given colon separated string. We are requiring that you use String methods to extract the individual sections as strings, and then use parseInt method calls to convert the strings to int’s for those that need it.



getPhoneNumber method with no arguments: (10%)

This is a standard accessor method that simply returns the colonSeparated instance variable’s value.



getPhoneNumber method with integer argument: (20%)

This method receives the position of one of the section (1, 2, 3, or 4) and returns the section that’s at that position. Area Code is 1, etc.
70%


NOTE: Complete your activity and submit it to the Dropbox.
5%

Total Points
100%

Sample Session:

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

1:919:882:5000

5000

1

882

919



Explanation / Answer

please rate - thanks

remember to change the words yourinitials to your initials


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

{

YourInitialsDissector phone = new YourInitialsDissector("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 YourInitialsDissector
{private int country, area, prefix, number;

public YourInitialsDissector(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;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote