Need this in Java with Eclipse also chegg stop closing my question this entire t
ID: 652033 • Letter: N
Question
Need this in Java with Eclipse also chegg stop closing my question this entire thing is one question. Answer it this time. I really despise this new system of asking questions.
Using the SinglyLinkedList classes built in class, make the proper modifications to make it a DoublyLinkedList. Then, write a simple text editor. Keep the entire text in a doubly linked list, storing each line in a separate node. The program begins with a line number as a prompt to enter text. From there, you have the following choices:
enter the letter I and a string S: this will insert the string S at the end
enter the letters IA, a line number N, and string S1: inserts S1 after line N
enter the letters IB, a line number N, and string S1: inserts S1 before line N
enter the letter D with a number N: deletes the Nth line of text
enter the letter L with a number N: lists the Nth line of text
enter the letters LA: lists all lines of text
enter the letter Q: quits the program
To support each of these operations, you will have the following methods in your DoublyLinkedList class:
insert: this method will take the line of text as a string and add it to the end of the list.
insertAfter: this method takes an integer parameter (used to indicate a line number) and a string parameter, and inserts the text after the appropriate node.
insertBefore: this method takes an integer parameter (used to indicate a line number) and a string parameter, and inserts the text before the appropriate node
deleteByPosition: this method will take an integer parameter indicating which element should be deleted. For example, if 3 is passed in, the 3rd element should be deleted.
printNode: this method takes an integer parameter of the node to print. For example, if 3 is passed in, it will print the 3rd node.
printAllNodes: this method takes no parameters and prints all nodes in the list.
Included are these
Assign04Driver.java: This should not be modified.
Node.java:This will need to be modified to support a doubly linked list.
DoublyLinkedList.java: A starter class for your doubly linked list. It includes method stubs which you must implement
TextEditor.java: You must not change this interface, nor can you remove the implementation of this interface from DoublyLinkedList.java.
Here is the code I have already for you.
https://www.dropbox.com/s/0710nej3882r86v/DoublyLinkedList.java?dl=0
https://www.dropbox.com/s/pmtqbf4pvryzamz/Assign04Driver.java?dl=0
https://www.dropbox.com/s/0m971tvrkz39pf5/Node.java?dl=0
https://www.dropbox.com/s/c59rr9j4qdhir39/TextEditor.java?dl=0
In the interface and DoublyLinkedList class, there are deleteNodes methods. Do nothing with those
Explanation / Answer
public class DDL
{
private Node head;
private int count;
public DDL()
{
head = new Node(null);
count = 0;
}
public void insert(Object data)
{
Node temp = new Node(data);
Node current = head;
while(current.getNext() != null)
{
current = current.getNext();
}
current.setNext(temp);
count++;
}
public void insertAfter(Object data, int index)
{
Node temp = new Node(data);
Node current = head;
for(int i = 1; i < index && current.getNext() != null; i++)
{current = current.getNext();}
temp.setNext(current.getNext());
current.setNext(temp);
count++;
}
public Object insertBefore(int index)
{
if(index <= 0)
return null;
Node current = head.getNext();
for(int i = 1; i < index; i++)
{
if(current.getNext() == null)
return null;
current = current.getNext();
}
return current.getData();
}
public boolean deleteByPosition(int index)
{
if(index < 1 || index > size())
return false;
Node current = head;
for(int i = 1; i < index; i++)
{
if(current.getNext() == null)
return false;
current = current.getNext();
}
current.setNext(current.getNext().getNext());
count--;
return true;
}
public String printNode()
{
Node current = head.getNext();
String output = "";
while(current != null)
{
output += "" + current.getData().toString() ;
current = current.getNext();
}
return output;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.