A linked list is built in this lab. Make sure to keep track of the head node. ContactNode.java - Class definition ContactList.java - Contains main() method (2) Build the ContactNode class per the following specifications: Private fields String contactName String contactPhoneNumber ContactNode nextNodePtr Constructor with parameters for name followed by phone number  Public member methods getName() - Accessor  getPhoneNumber() - Accessor  insertAfter()  getNext() - Accessor  printContactNode() Ex: If the name is Roxanne Hughes and the phone number is 443-555-2864, printContactNode() outputs: Name: Roxanne Hughes Phone number: 443-555-2864 (3) Define main() to read the name and phone number for three contacts and output each contact. Create three ContactNodes and use the nodes to build a linked list.  Ex: If the input is: Roxanne Hughes 443-555-2864 Juan Alberto Jr. 410-555-9385 Rachel Phillips 310-555-6610 the output is: Person 1: Roxanne Hughes, 443-555-2864 Person 2: Juan Alberto Jr., 410-555-9385 Person 3: Rachel Phillips, 310-555-6610 (4) Output the linked list using a loop to output contacts one at a time.  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 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);             }         }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

A linked list is built in this lab. Make sure to keep track of the head node.

  • ContactNode.java - Class definition
  • ContactList.java - Contains main() method

(2) Build the ContactNode class per the following specifications:

  • Private fields
    • String contactName
    • String contactPhoneNumber
    • ContactNode nextNodePtr
  • Constructor with parameters for name followed by phone number 
  • Public member methods
    • getName() - Accessor 
    • getPhoneNumber() - Accessor 
    • insertAfter() 
    • getNext() - Accessor 
    • printContactNode()

Ex: If the name is Roxanne Hughes and the phone number is 443-555-2864, printContactNode() outputs:

Name: Roxanne Hughes Phone number: 443-555-2864

(3) Define main() to read the name and phone number for three contacts and output each contact. Create three ContactNodes and use the nodes to build a linked list. 

Ex: If the input is:

Roxanne Hughes 443-555-2864 Juan Alberto Jr. 410-555-9385 Rachel Phillips 310-555-6610

the output is:

Person 1: Roxanne Hughes, 443-555-2864 Person 2: Juan Alberto Jr., 410-555-9385 Person 3: Rachel Phillips, 310-555-6610

(4) Output the linked list using a loop to output contacts one at a time. 

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

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:**

- Roxanne Hughes  
  443-555-2864
- Juan Alberto Jr.  
  410-555-9385
- Rachel Phillips  
  310-555-6610

**Your Output Starts With:**

- Person 1: 
  - Name: Roxanne   
  - Phone number: Hughes
- Person 2: 
  - Name: 443-555-2864  
  - Phone number: Juan
- Person 3: 
  - Name: Alberto  
  - Phone number: Jr.

**Expected Output Starts With:**

- Person 1: Roxanne Hughes, 443-555-2864
- Person 2: Juan Alberto Jr., 410-555-9385
- Person 3: Rachel Phillips, 310-555-6610

**Explanation:**

The image contains a comparison between an incorrectly formatted output and the expected output of a text processing task. The task involves identifying names and phone numbers from a given list. The expected format lists each person's full name followed by their phone number. The "Your Output" section demonstrates an error where names and phone numbers are mismatched, leading to incorrect pairings.  

This visual breakdown is important for understanding how to properly parse and format data.
Transcribed Image Text:**Input:** - Roxanne Hughes 443-555-2864 - Juan Alberto Jr. 410-555-9385 - Rachel Phillips 310-555-6610 **Your Output Starts With:** - Person 1: - Name: Roxanne - Phone number: Hughes - Person 2: - Name: 443-555-2864 - Phone number: Juan - Person 3: - Name: Alberto - Phone number: Jr. **Expected Output Starts With:** - Person 1: Roxanne Hughes, 443-555-2864 - Person 2: Juan Alberto Jr., 410-555-9385 - Person 3: Rachel Phillips, 310-555-6610 **Explanation:** The image contains a comparison between an incorrectly formatted output and the expected output of a text processing task. The task involves identifying names and phone numbers from a given list. The expected format lists each person's full name followed by their phone number. The "Your Output" section demonstrates an error where names and phone numbers are mismatched, leading to incorrect pairings. This visual breakdown is important for understanding how to properly parse and format data.
The image shows a comparison between an input contact list, an incorrect output, and the expected correct output.

**Input:**
- Roxanne Hughes
  443-555-2864
- Juan Alberto Jr.
  410-555-9385
- Rachel Phillips
  310-555-6610

**Your Output:**
The output has misalignment and errors. The text is formatted incorrectly, leading to a jumbled presentation:
- Person 2: Name: Roxanne Phone number: Hughes
- 443-555-2864 Phone number: Juan
- Person 3: Name: Alberto Phone number: Jr.

**Expected Output:**
The expected output provides a neatly formatted contact list:
- **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

In this corrected format, each contact's name is clearly associated with their respective phone number.
Transcribed Image Text:The image shows a comparison between an input contact list, an incorrect output, and the expected correct output. **Input:** - Roxanne Hughes 443-555-2864 - Juan Alberto Jr. 410-555-9385 - Rachel Phillips 310-555-6610 **Your Output:** The output has misalignment and errors. The text is formatted incorrectly, leading to a jumbled presentation: - Person 2: Name: Roxanne Phone number: Hughes - 443-555-2864 Phone number: Juan - Person 3: Name: Alberto Phone number: Jr. **Expected Output:** The expected output provides a neatly formatted contact list: - **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 In this corrected format, each contact's name is clearly associated with their respective phone number.
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education