Question
Hopefully you're getting the idea now. This lab has you using composition on the Name and PhoneNumber classes of the previous two labs to create
Hopefully you're getting the idea now. This lab has you using composition on the Name and PhoneNumber classes of the previous two labs to create a third, more complex class named PhonebookEntry. The basic structure is the same only now you will be employing methods of the previous two classes when coding this new class. The state for this class is:
An instance variable of type Name named name
An instance variable of type PhoneNumber named phoneNumber
and the behavior is:
a constructor that accepts a Name object and a PhoneNumber obejet and assigns them to the corresponding instance variables
A method, call that displays a message that the phone number is begin called (together with an indication of the call is toll-free).
toString, equals, and read methods that correspond to their counterparts in the Name class.
a main method with similar logic to before:
open the file phonebook.text
read in PhonebookeEnry objects
print out the entry
invoke the call method on them
if two adjacent names are the same, but not the numbers,print a message to that effect, but still print out the data for the second entry
if two adjacent entries are the same (name AND number), print out a duplicate error message (as inthe previous classes)
keep track of the number of entries processed
The name of your class should be PhonebookEntry. Please remove the public attribute from your class definition (CodeLab restriction).
For example, if the file phonebook.text contains:
Edwards Steven (356)153-9460 Carter Joshua (290)261-7625 Carter Joshua (761)321-9457 Jackson Anthony (724)091-7819 Carter Barbara (759)301-3133 Evans Edward (072)023-0203 White Christopher (060)075-3782 White Christopher (060)075-3782 Taylor Michelle (369)348-9660 Baker Melissa (844)824-5853 Young Anthony (692)839-8466 Hall Michael (216)386-2922
the program should produce the following output:
phone book entry: Steven Edwards: (356)153-9460 Dialing Steven Edwards: (356)153-9460 phone book entry: Joshua Carter: (290)261-7625 Dialing Joshua Carter: (290)261-7625 Warning duplicate name encountered "Joshua Carter: (761)321-9457" discovered phone book entry: Joshua Carter: (761)321-9457 Dialing Joshua Carter: (761)321-9457 phone book entry: Anthony Jackson: (724)091-7819 Dialing Anthony Jackson: (724)091-7819 phone book entry: Barbara Carter: (759)301-3133 Dialing Barbara Carter: (759)301-3133 phone book entry: Edward Evans: (072)023-0203 Dialing Edward Evans: (072)023-0203 phone book entry: Christopher White: (060)075-3782 Dialing Christopher White: (060)075-3782 Duplicate phone book entry "Christopher White: (060)075-3782" discovered phone book entry: Michelle Taylor: (369)348-9660 Dialing Michelle Taylor: (369)348-9660 phone book entry: Melissa Baker: (844)824-5853 Dialing (toll-free) Melissa Baker: (844)824-5853 phone book entry: Anthony Young: (692)839-8466 Dialing Anthony Young: (692)839-8466 phone book entry: Michael Hall: (216)386-2922 Dialing Michael Hall: (216)386-2922 --- 12 phonebook entries processed.
****** Previous example with the name class
class Name {
public Name(String last, String first) {
this.last = last;
this.first = first;
}
public Name(String first) {
this("", first);
}
public String getFormal() {
return first + " " + last;
}
public String getOfficial() {
return last + ", " + first;
}
public boolean equals(Name other) {
return first.equals(other.first) && last.equals(other.last);
}
public String toString() {
return first + " " + last;
}
public static Name read(Scanner scanner) {
if (!scanner.hasNext())
return null;
String last = scanner.next();
String first = scanner.next();
return new Name(last, first);
}
public String getInitials() {
String intials = this.first.charAt(0) + "." + this.last.charAt(0) + ".";
return intials;
}
private String first, last;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started