Input Your output Expected output Roxanne Hughes 443-555-2864 Juan Alberto Jr. 410-555-9385 Rachel Phillips 310-555-6610 1: 1: 2: 2: 3: 3: Person 1: Name: Roxanne Phone number: Hughes Person 2: Name: 443-555-2864 Phone number: Juane Person 3: Name: Alberto Phone number: Jr. Person 1: Roxanne Hughes, 443-555-28644 Person 2: Juan Alberto Jr., 410-555-93854 Person 3: Rachel Phillips, 310-555-66104 CONTACT LIST Name: Roxanne Hughes Phone number: 443-555-28644 Name: Juan Alberto Jr. Phone number: 410-555-93854 Name: Rachel Phillips Phone number: 310-555-6610
import java.util.Scanner;
public class ContactList {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
ContactNode head = null;
ContactNode current = null;
// Read the name and phone number for three contacts and build a linked list.
for (int i = 1; i <= 3; i++) {
System.out.print(" " + i + ": ");
String name = scnr.next();
System.out.print(" " + i + ": ");
String phoneNumber = scnr.next();
ContactNode newContact = new ContactNode(name, phoneNumber);
if (head == null) {
head = newContact;
current = head;
} else {
current.insertAfter(newContact);
current = newContact;
}
}
// Output each contact.
current = head;
for (int i = 1; current != null; i++) {
System.out.print("Person " + i + ": ");
current.printContactNode();
current = current.getNext();
}
}
}
class ContactNode {
private String contactName;
private String contactPhoneNumber;
private ContactNode nextNodePtr;
public ContactNode(String name, String phoneNumber) {
this.contactName = name;
this.contactPhoneNumber = phoneNumber;
this.nextNodePtr = null;
}
public String getName() {
return contactName;
}
public String getPhoneNumber() {
return contactPhoneNumber;
}
public ContactNode getNext() {
return nextNodePtr;
}
public void insertAfter(ContactNode node) {
ContactNode temp = this.nextNodePtr;
this.nextNodePtr = node;
node.nextNodePtr = temp;
}
public void printContactNode() {
System.out.println("Name: " + contactName + " Phone number: " + contactPhoneNumber);
}
}
![Input
Your output
Expected output
Roxanne Hughes
443-555-2864
Juan Alberto Jr.
410-555-9385
Rachel Phillips.
310-555-6610
1: 1: 2: 2:
Person 2: Name:
Person 3: Name: Alberto Phone number: Jr.
3: 3: Person 1: Name: Roxanne Phone number: Hughes
443-555-2864 Phone number: Juane
Person 1: Roxanne Hughes, 443-555-28644
Person 2: Juan Alberto Jr., 410-555-93854
Person 3: Rachel Phillips, 310-555-66104
CONTACT LIST
Name: Roxanne Hughes
Phone number: 443-555-28644
Name: Juan Alberto Jr.d
Phone number: 410-555-93854
Name: Rachel Phillips
Phone number: 310-555-6610](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa3dbb91f-777d-47b2-aa94-40b3e17142a5%2F4478b38f-5a01-4188-96ab-d32ef6d4ef21%2Fugg5mos_processed.png&w=3840&q=75)
![Input
Your output starts
with
Expected output
starts with
Roxanne Hughes
443-555-2864
Juan Alberto Jr.
410-555-9385
Rachel Phillips
310-555-6610
1: 2: 2:
1:
3: 3: Person 1: Name: Roxanne Phone number: Hughes
Person 2: Name: 443-555-2864 Phone number: Juan
Person 3: Name: Alberto Phone
Person 1: Roxanne Hughes, 443-555-2864
Person 2: Juan Alberto Jr., 410-555-9385
Person 3: Rachel Phillips, 310-555-6610](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa3dbb91f-777d-47b2-aa94-40b3e17142a5%2F4478b38f-5a01-4188-96ab-d32ef6d4ef21%2Fdna3utg_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)