1. Implement a phone book using a linked list structure. In this phone book, you are going to store a name, last name, email, and phone number. 2. Implement an insert operation to the phone book. With the insert operation, you're going to add the name, last

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

Use Java

**Phonebook with LinkedList**

1. **Task**: Implement a phone book using a linked list structure. In this phone book, you will store a name, last name, email, and phone number.

2. **Insert Operation**: Implement an insert operation to add the name, last name, email, and phone number of the person to the phone book.

3. **Methods to Implement**:
   - **findByName**: Will return the information of the first record matching the name you send.
   - **findAllByLastName**: Will return an ArrayList of all entries matching the last name you send.
   - **deleteByName**: Will delete the first record matching the name you send to this method.
   - **deleteAllMatchingLastName**: Will delete all entries matching the last name.
   - **findAll**: Return all records as an ArrayList.
   - **printPhoneBook**: Will print all entries in the phone book.

---

**Discussion**: Let’s discuss the following after you do the above task.

1. What is the time complexity of the above operations?
2. How can we come up with O(1) with the findByName operation? (lovely hash map)
Transcribed Image Text:**Phonebook with LinkedList** 1. **Task**: Implement a phone book using a linked list structure. In this phone book, you will store a name, last name, email, and phone number. 2. **Insert Operation**: Implement an insert operation to add the name, last name, email, and phone number of the person to the phone book. 3. **Methods to Implement**: - **findByName**: Will return the information of the first record matching the name you send. - **findAllByLastName**: Will return an ArrayList of all entries matching the last name you send. - **deleteByName**: Will delete the first record matching the name you send to this method. - **deleteAllMatchingLastName**: Will delete all entries matching the last name. - **findAll**: Return all records as an ArrayList. - **printPhoneBook**: Will print all entries in the phone book. --- **Discussion**: Let’s discuss the following after you do the above task. 1. What is the time complexity of the above operations? 2. How can we come up with O(1) with the findByName operation? (lovely hash map)
# Phonebook with LinkedList

## 1. Implement a Phonebook Using a Linked List Structure

In this phonebook, you are going to store:
- Name
- Last Name
- Email
- Phone Number

### Code Overview

#### PhoneBookNode Class

```java
public class PhoneBookNode {
    public Contact contact;
    public PhoneBookNode next;
    
    public PhoneBookNode(Contact contact) {
        this.contact = contact;
    }
}
```

- This Node class is designed for a singly linked list node implementation.
- The `contact` object is responsible for holding the value.
- It is a different version of the Node class used before.

#### Contact Class

```java
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class Contact {
    public String firstName;
    public String lastName;
    public String email;
    public String phoneNumber;
}
```

- The `Contact` class holds the details like `firstName`, `lastName`, `email`, and `phoneNumber`.

#### ListNode Example

```java
static class ListNode {
    int value;
    ListNode next;
    
    ListNode(int x) {
        value = x;
    }
}
```

- This class is part of a standard singly linked list implementation.

### Description

- The PhoneBookNode class serves as the building block for our phonebook linked list. It connects `Contact` objects in a sequence.
- The Contact class uses annotations for automatic constructor generation and object string representation.
- The static ListNode class demonstrates basic linked list node structure, aiming to visualize linked node concepts.

This is a foundational implementation of a phonebook using linked list data structures, suitable for educational purposes in understanding linked lists and class design in Java.
Transcribed Image Text:# Phonebook with LinkedList ## 1. Implement a Phonebook Using a Linked List Structure In this phonebook, you are going to store: - Name - Last Name - Email - Phone Number ### Code Overview #### PhoneBookNode Class ```java public class PhoneBookNode { public Contact contact; public PhoneBookNode next; public PhoneBookNode(Contact contact) { this.contact = contact; } } ``` - This Node class is designed for a singly linked list node implementation. - The `contact` object is responsible for holding the value. - It is a different version of the Node class used before. #### Contact Class ```java @NoArgsConstructor @AllArgsConstructor @ToString public class Contact { public String firstName; public String lastName; public String email; public String phoneNumber; } ``` - The `Contact` class holds the details like `firstName`, `lastName`, `email`, and `phoneNumber`. #### ListNode Example ```java static class ListNode { int value; ListNode next; ListNode(int x) { value = x; } } ``` - This class is part of a standard singly linked list implementation. ### Description - The PhoneBookNode class serves as the building block for our phonebook linked list. It connects `Contact` objects in a sequence. - The Contact class uses annotations for automatic constructor generation and object string representation. - The static ListNode class demonstrates basic linked list node structure, aiming to visualize linked node concepts. This is a foundational implementation of a phonebook using linked list data structures, suitable for educational purposes in understanding linked lists and class design in Java.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Threads in linked list
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.
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