Question

I am stuck for this. I understand the what I need to do but I am...

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//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;
}
}

Add a comment
Know the answer?
Add Answer to:
I am stuck for this. I understand the what I need to do but I am...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT