23.14 Ch 8 Warm up: Contacts (Java) Students: This content is controlled by your
ID: 3818996 • Letter: 2
Question
23.14 Ch 8 Warm up: Contacts (Java)
Students:
This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom of the lab.
You will be building a linked list. Make sure to keep track of both the head and tail nodes.
(1) Create two files to submit.
ContactNode.java - Class definitionContactList.java - Contains main() method
(2) Build the ContactNode class per the following specifications:
Parameterized constructor. Parameters are name followed by phone number.
Private fields
String contactNameString contactPhoneNumberContactNode nextNodePtr
Public member methods
getName() - Accessor (1 pt)getPhoneNumber - Accessor (1 pt)insertAfter() (2 pts)getNext() - Accessor (1 pt)printContactNode()
Ex. of printContactNode() output:
Name: Roxanne Hughes Phone number: 443-555-2864
(3) In main(), prompt the user for three contacts and output the user's input. Create three ContactNodes and use the nodes to build a linked list. (2 pts)
Ex:
Person 1 Enter name: Roxanne Hughes Enter phone number: 443-555-2864 You entered: Roxanne Hughes, 443-555-2864 Person 2 Enter name: Juan Alberto Jr. Enter phone number: 410-555-9385 You entered: Juan Alberto Jr., 410-555-9385 Person 3 Enter name: Rachel Phillips Enter phone number: 310-555-6610 You entered: Rachel Phillips, 310-555-6610
(4) Output the linked list. (2 pts)
Ex:
CONTACT LIST Name: Roxanne Hughes Phone number: 443-555-2864 Name: Juan Alberto Jr. Phone number: 410-555-9385 Name: Rachel Phillips Phone number: 310-555-6610
Explanation / Answer
Please find the program below:
ContactNode.java
class ContactNode {
private String contactName;
private String contactPhoneNumber;
private ContactNode nextNodePtr;
public ContactNode (String cName, String cPhoneNumber, ContactNode nextNode )
{
this.contactName=cName;
this.contactPhoneNumber=cPhoneNumber;
this.nextNodePtr=nextNode ;
}
public getName(){
return contactName;
}
public getPhoneNumber(){
return contactPhoneNumber;
}
public insertAfter(ContactNode currentNode, ContactNode newNode){
ContactNode next = currentNode.getNext();
currentNode.setNext(newNode);
newNode.setNext(next);
public getNext(){
return nextNodePtr;
}
public printContactNode(){
System.out.println("Name "+contactName+" Phone Number "+contactPhoneNumber+" "):
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.