Add more methods to the doubly linked list class then test them • search(e) // Return one node with 3 values (stuID, stuName, stuScore) which matches a given key e (studentID). • addAfter(e, stuID, stuName, stuScore) //Add a new node with 3 values (stuID, stuName, stuScore) after the node with the key e (studentID). • removeAt(e) //Remove a node which matches a given key e (studentID) • count() //Return a number of nodes of list. • update(stuID, stuName, stuScore) //Update the values of one node first code below  package DlinkedList; public class DLinkedList {     private Node header;     private Node trailer;     private int size;          public DLinkedList() {         header = new Node<>(null, null, null);         trailer = new Node<>(null, null, null);         header.setNext(trailer);         trailer.setPrev(header);              }     public int getSize() {         return size;     }     public boolean isEmpty() {         return size==0;     }     public A getFirstStuID() {         return header.getNext().getStuID();     }     public B getFirstStuName() {         return header.getNext().getStuName();     }     public C getFirstStuScore() {         return header.getNext().getStuScore();          }          public A getLastStuID() {         return trailer.getPrev().getStuID();     }     public B getLastStuName() {         return trailer.getPrev().getStuName();     }     public C getLastStuScore() {         return trailer.getPrev().getStuScore();     }          private void addBetween(A id, B name, C score, Node predecessor, Node successor) {         Node newest = new Node<>(id, name, score);         newest.setPrev(predecessor);         newest.setNext(successor);         predecessor.setNext(newest);         successor.setPrev(newest);         size++;         }     public void addFirst(A id, B name, C score) {         addBetween(id, name,score,header,header.getNext());     }     public void addLast(A id, B name, C score) {         addBetween(id, name,score, trailer.getPrev(), trailer);     }     private Node remove(Node node){         Node predecessor = node.getPrev();         Node successor = node.getNext();         predecessor.setNext(successor);         successor.setPrev(predecessor);         size--;         return node;     }     public Node removeFirst(){         if(isEmpty())             return null;         return remove(header.getNext());     }     public Node removeLast(){         if(isEmpty())             return null;         return remove(trailer.getPrev());     }     public Node search(A key){         if(isEmpty())             return null;         Node temp = header.getNext();         do{             if(temp.getStuID()== key)                 return temp;             temp = temp.getNext();             }while ( temp != null);         return null;     }          public void addAfter(A key, A id, B name, C score) {         if(isEmpty())             return;         Node node = search(key);         if(node == null)        return;         addBetween(id, name, score, node, node.getNext());     }          public void display() {         if(isEmpty()) {             System.out.println("Linked list is empty.");             return;         }         Node temp = header.getNext();         do {             temp.displayNode();             temp = temp.getNext();         }while(temp.getNext() !=null);     }     public void addBefore(A key, A id, B name, C score) {         if(isEmpty())             return;         Node node = search(key);         if(node == null)             return;         addBetween( id, name, score, node.getPrev(), node);     }     public Node removeAt( A key){         if (isEmpty())             return null;         Node node = search(key);         if(node == null)             return null;         return remove(node);     }     public Node update(A key, A nid, B nname, C nscore){         if(isEmpty())             return null;         Node node = search(key);         if(node == null)             return null;         node.setStuID(nid);         node.setStuName(nname);         node.setStuScore(nscore);         return node;     } }

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

Add more methods to the doubly linked list class then test them
• search(e) // Return one node with 3 values (stuID, stuName, stuScore) which matches a
given key e (studentID).
• addAfter(e, stuID, stuName, stuScore) //Add a new node with 3 values (stuID,
stuName, stuScore) after the node with the key e (studentID).
• removeAt(e) //Remove a node which matches a given key e (studentID)
• count() //Return a number of nodes of list.
• update(stuID, stuName, stuScore) //Update the values of one node

first code below 

package DlinkedList;
public class DLinkedList<A,B,C> {
    private Node<A,B,C> header;
    private Node<A,B,C> trailer;
    private int size;
    
    public DLinkedList() {
        header = new Node<>(null, null, null);
        trailer = new Node<>(null, null, null);
        header.setNext(trailer);
        trailer.setPrev(header);
        
    }
    public int getSize() {
        return size;
    }
    public boolean isEmpty() {
        return size==0;
    }
    public A getFirstStuID() {
        return header.getNext().getStuID();
    }
    public B getFirstStuName() {
        return header.getNext().getStuName();
    }
    public C getFirstStuScore() {
        return header.getNext().getStuScore();
    
    }
    
    public A getLastStuID() {
        return trailer.getPrev().getStuID();
    }
    public B getLastStuName() {
        return trailer.getPrev().getStuName();
    }
    public C getLastStuScore() {
        return trailer.getPrev().getStuScore();
    }
    
    private void addBetween(A id, B name, C score, Node<A,B,C> predecessor, Node<A,B,C> successor) {
        Node<A,B,C> newest = new Node<>(id, name, score);
        newest.setPrev(predecessor);
        newest.setNext(successor);
        predecessor.setNext(newest);
        successor.setPrev(newest);
        size++;
        }
    public void addFirst(A id, B name, C score) {
        addBetween(id, name,score,header,header.getNext());
    }
    public void addLast(A id, B name, C score) {
        addBetween(id, name,score, trailer.getPrev(), trailer);
    }
    private Node<A,B,C> remove(Node<A,B,C> node){
        Node<A,B,C> predecessor = node.getPrev();
        Node<A,B,C> successor = node.getNext();
        predecessor.setNext(successor);
        successor.setPrev(predecessor);
        size--;
        return node;
    }
    public Node<A,B,C> removeFirst(){
        if(isEmpty())
            return null;
        return remove(header.getNext());
    }
    public Node<A,B,C> removeLast(){
        if(isEmpty())
            return null;
        return remove(trailer.getPrev());
    }
    public Node<A,B,C> search(A key){
        if(isEmpty())
            return null;
        Node<A,B,C> temp = header.getNext();
        do{
            if(temp.getStuID()== key)
                return temp;
            temp = temp.getNext();
            }while ( temp != null);
        return null;
    }
    
    public void addAfter(A key, A id, B name, C score) {
        if(isEmpty())
            return;
        Node<A,B,C> node = search(key);
        if(node == null)
       return;
        addBetween(id, name, score, node, node.getNext());
    }
    
    public void display() {
        if(isEmpty()) {
            System.out.println("Linked list is empty.");
            return;
        }
        Node<A,B,C> temp = header.getNext();
        do {
            temp.displayNode();
            temp = temp.getNext();
        }while(temp.getNext() !=null);
    }
    public void addBefore(A key, A id, B name, C score) {
        if(isEmpty())
            return;
        Node<A,B,C> node = search(key);
        if(node == null)
            return;
        addBetween( id, name, score, node.getPrev(), node);
    }
    public Node<A,B,C> removeAt( A key){
        if (isEmpty())
            return null;
        Node<A,B,C> node = search(key);
        if(node == null)
            return null;
        return remove(node);
    }
    public Node<A,B,C> update(A key, A nid, B nname, C nscore){
        if(isEmpty())
            return null;
        Node<A,B,C> node = search(key);
        if(node == null)
            return null;
        node.setStuID(nid);
        node.setStuName(nname);
        node.setStuScore(nscore);
        return node;
    }
}

The image contains Java code for a class named `TwistyPasta`. The code appears to be designed to output text, displayed using the `System.out.println()` method, and involves a series of nested loops.

```java
package twistypasta;

public class TwistyPasta {
    public static void main(String[] args) {
        
        // First loop
        for (int i = 1; i <= 5; i++) {
            System.out.print("*");
            System.out.print("#");
            System.out.print("!");
            System.out.print("@");
            System.out.print(">");
            System.out.print("<");
            System.out.print(".");
            System.out.print("/");
            System.out.println("\\");
        }

        // Second loop
        while (true) {
            System.out.print("$");
            System.out.println("%");
            try {
                Thread.sleep(1000); // Pauses for 1 second
            } catch (InterruptedException e) {}
        }

        // Third loop
        for (int i = 0; i < 5; i++) {
            System.out.println("Twist");
        }

        // Fourth loop
        String[] array = {"A", "B", "C"};
        for (String s : array) {
            System.out.print(s);
            System.out.println("Loop");
        }
        
    }
}
```

### Explanation of Code Structure:

1. **Package Declaration:**
   - `package twistypasta;` indicates that this class belongs to the `twistypasta` package.

2. **Class Definition:**
   - `public class TwistyPasta {}` defines a public class named `TwistyPasta`.

3. **Main Method:**
   - The entry point of the program is `public static void main(String[] args) {}`.

4. **First Loop:**
   - A `for` loop runs five times, printing a sequence of symbols (`*`, `#`, `!`, `@`, `>`, `<`, `.`, `/`, `\`) each time.

5. **Second Loop:**
   - An infinite `while` loop continuously prints `$` followed by `%` with a one-second pause between iterations using `Thread.sleep(1000)`.

6. **Third Loop:**
   - A `for` loop prints the word "Twist" five times.

7. **Fourth Loop:**
   - A `for-each`
Transcribed Image Text:The image contains Java code for a class named `TwistyPasta`. The code appears to be designed to output text, displayed using the `System.out.println()` method, and involves a series of nested loops. ```java package twistypasta; public class TwistyPasta { public static void main(String[] args) { // First loop for (int i = 1; i <= 5; i++) { System.out.print("*"); System.out.print("#"); System.out.print("!"); System.out.print("@"); System.out.print(">"); System.out.print("<"); System.out.print("."); System.out.print("/"); System.out.println("\\"); } // Second loop while (true) { System.out.print("$"); System.out.println("%"); try { Thread.sleep(1000); // Pauses for 1 second } catch (InterruptedException e) {} } // Third loop for (int i = 0; i < 5; i++) { System.out.println("Twist"); } // Fourth loop String[] array = {"A", "B", "C"}; for (String s : array) { System.out.print(s); System.out.println("Loop"); } } } ``` ### Explanation of Code Structure: 1. **Package Declaration:** - `package twistypasta;` indicates that this class belongs to the `twistypasta` package. 2. **Class Definition:** - `public class TwistyPasta {}` defines a public class named `TwistyPasta`. 3. **Main Method:** - The entry point of the program is `public static void main(String[] args) {}`. 4. **First Loop:** - A `for` loop runs five times, printing a sequence of symbols (`*`, `#`, `!`, `@`, `>`, `<`, `.`, `/`, `\`) each time. 5. **Second Loop:** - An infinite `while` loop continuously prints `$` followed by `%` with a one-second pause between iterations using `Thread.sleep(1000)`. 6. **Third Loop:** - A `for` loop prints the word "Twist" five times. 7. **Fourth Loop:** - A `for-each`
The image shows a Java class definition for a generic linked list node, which uses three generic parameters: A, B, and C. The class is named `Node<A, B, C>`. Below is a transcription and explanation of the code:

### Code Explanation

- **Class Definition:**
  ```java
  class Node<A, B, C> {
  ```

- **Private Variables:**
  - `stuID`: of type `A`, storing the ID.
  - `stuName`: of type `B`, storing the name.
  - `stuScore`: of type `C`, storing the score.
  - `next`: a reference to the next node.
  - `prev`: a reference to the previous node.

  ```java
      private A stuID;
      private B stuName;
      private C stuScore;
      private Node<A, B, C> next;
      private Node<A, B, C> prev;
  ```

- **Constructor:**
  Initializes a node with given ID, name, and score. Sets `next` and `prev` to null initially.
  
  ```java
      public Node(A id, B name, C score) {
          stuID = id;
          stuName = name;
          stuScore = score;
          next = null;
          prev = null;
      }
  ```

- **Getters:**
  Methods to get the values of `stuID`, `stuName`, `stuScore`, `next`, and `prev`.

  ```java
      public A getStuID() {
          return stuID;
      }
  
      public B getStuName() {
          return stuName;
      }
  
      public C getStuScore() {
          return stuScore;
      }
  
      public Node<A, B, C> getNext() {
          return next;
      }
  
      public Node<A, B, C> getPrev() {
          return prev;
      }
  ```

- **Setters:**
  Methods to set the values of `stuID`, `stuName`, `stuScore`, `next`, and `prev`.

  ```java
      public void setStuID(A ID) {
          stuID = ID;
      }
  
      public void setStuName(B name) {
          stuName = name;
      }
  
      public void setStuScore(C score) {
          stuScore = score;
      }
Transcribed Image Text:The image shows a Java class definition for a generic linked list node, which uses three generic parameters: A, B, and C. The class is named `Node<A, B, C>`. Below is a transcription and explanation of the code: ### Code Explanation - **Class Definition:** ```java class Node<A, B, C> { ``` - **Private Variables:** - `stuID`: of type `A`, storing the ID. - `stuName`: of type `B`, storing the name. - `stuScore`: of type `C`, storing the score. - `next`: a reference to the next node. - `prev`: a reference to the previous node. ```java private A stuID; private B stuName; private C stuScore; private Node<A, B, C> next; private Node<A, B, C> prev; ``` - **Constructor:** Initializes a node with given ID, name, and score. Sets `next` and `prev` to null initially. ```java public Node(A id, B name, C score) { stuID = id; stuName = name; stuScore = score; next = null; prev = null; } ``` - **Getters:** Methods to get the values of `stuID`, `stuName`, `stuScore`, `next`, and `prev`. ```java public A getStuID() { return stuID; } public B getStuName() { return stuName; } public C getStuScore() { return stuScore; } public Node<A, B, C> getNext() { return next; } public Node<A, B, C> getPrev() { return prev; } ``` - **Setters:** Methods to set the values of `stuID`, `stuName`, `stuScore`, `next`, and `prev`. ```java public void setStuID(A ID) { stuID = ID; } public void setStuName(B name) { stuName = name; } public void setStuScore(C score) { stuScore = score; }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

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.
Similar 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