.The Contact class contains the name and the phone number of a contact, and prov
ID: 3703863 • Letter: #
Question
.The Contact class contains the name and the phone number of a contact, and provide a few methods, including the method to add a phone number. Write the code for the Contact class as shown in the class model below. See Contact.java for the details of individual methods. Do not create getter/setter methods for the instance variables. You do not need those for this assignment Contact -Name name -String phoneNumber +Contact(Name name) +boolean equals(Object c) +String toString0 +boolean addPhoneNumber(String pNumber)Explanation / Answer
public boolean addPhoneNumber(String pNumber) { if(pNumber.length() == 12) { if(java.lang.Character.isDigit(pNumber.charAt(0)) && java.lang.Character.isDigit(pNumber.charAt(1)) && java.lang.Character.isDigit(pNumber.charAt(2)) && java.lang.Character.isDigit(pNumber.charAt(4)) && java.lang.Character.isDigit(pNumber.charAt(5)) && java.lang.Character.isDigit(pNumber.charAt(6)) && java.lang.Character.isDigit(pNumber.charAt(8)) && java.lang.Character.isDigit(pNumber.charAt(9)) && java.lang.Character.isDigit(pNumber.charAt(10)) && java.lang.Character.isDigit(pNumber.charAt(11)) && pNumber.charAt(3) == '-' && pNumber.charAt(7) == '-') { phoneNumber = pNumber; return true; } else { return false; } } else { return false; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.