I am stuck for this. I understand the what I need to do but I am having trouble typing it out
Write the class, PhoneNumber.java. Do the following: 1. Create three instance variables, countryCode, areaCode and number, all of which should be Strings. 2. Write the default constructor. 3. Write the non-default constructor. 4. Write 3 accessor methods, one for each instance variable. 5. Write 3 mutator methods, one for each instance variable. 6. Write a method that will return the entire phone number as a single string (the toString method). 7. Write a method that will return true if the areaCode is 3 characters long. 8. Write a method that will return true if the number is 7 characters long. 9. Optional: 7 and 8 return true if the areaCode is 3 digit characters long and the number is 7 digit characters long. 10. Now write an application class that instantiates two instances of PhoneNumber. One instance should use the default constructor and the other should use the non-default constructor. Display the values of each object by calling the toString method.
//as per HomeworkLib policy we attempt only 4 parts if there are
multiple questions
//skipped from part 9 as it is optional, please comment if you want
full answer.
public class PhoneNumber {
//part 1
private String countryCode,areaCode,number;
//part2
public PhoneNumber()
{ this.countryCode = "";
this.areaCode = "";
this.number = "";
}
//part 3
public PhoneNumber(String countryCode, String areaCode, String
number) {
this.countryCode = countryCode;
this.areaCode = areaCode;
this.number = number;
}
//part 4
public String getCountryCode() {
return countryCode;
}
public String getAreaCode() {
return areaCode;
}
public String getNumber() {
return number;
}
//part 5
public void setCountryCode(String countryCode) {
this.countryCode = countryCode;
}
public void setAreaCode(String areaCode) {
this.areaCode = areaCode;
}
public void setNumber(String number) {
this.number = number;
}
//part 6
@Override
public String toString() {
return "PhoneNumber: " + countryCode+"-" + areaCode +
"-" + number;
}
//part 7
public boolean isAreacode_len3()
{if(areaCode.length()==3)
return true;
return false;
}
//part 8
public boolean isnum_len7()
{if(number.length()==7)
return true;
return false;
}
}