Need this in Java with Eclipse follow the code I already did below and make sure
ID: 652305 • Letter: N
Question
Need this in Java with Eclipse follow the code I already did below and make sure it works with it also chegg stop closing my question this entire thing is one question. Please 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
Please read the whole thing and make sure you do the question correctly please. My last two answers from the same question were not great.
Explanation / Answer
public class Node<E>
{
E data;
Node<E> next;
Node<E> pre;
public Node(E d)
{
data = d;
}
}
[4:02:23 PM] BHAVANI RAGHU: public class DoublyLinkedList<E> implements TextEditor<E>
{
Node<E> head;
Node<E> tail;
public DoublyLinkedList()
{
head = null;
tail=null;
}
public boolean isEmpty()
{
return (head == null);
}
public void insert(E line)
{
Node<E> x = new Node();
x.data = line;
x.next=null;
tail.next=x;
x.prev=tail;
tail=x;
}
}
public void insertAfter(int lineNum, E line)
{
Node<E> temp;
Node<E> x = new Node();
x.data=line;
for(int i=0,temp=head;i<lineNum;i++)
temp=temp.next;
x.next=temp.next;
temp.prev =x;
x.prev=temp;
}
public void insertBefore(int lineNum, E line)
{
Node<E> temp;
Node<E> x = new Node();
x.data=line;
for(int i=0,temp=tail;i<lineNum;i--)
temp=temp.next;
x.prev=temp.prev;
temp.prev =x;
x.next=temp;`
}
public void deleteByPosition(int position)
{
Node<E> temp,temp1;
int flag=1;
for(int i=0,temp=tail;i<position;i--)
{ temp1=temp;
temp=temp.next;
flag=0;}
if(flag)
{
tail=tail.prev;
tail.next=null;
}
temp1.prev=temp.prev;
temp.prev.next=temp1;
if(temp.prev!=null)
head=temp.next;
temp=null;
}
public void deleteNodes(E startPos, E endPos)
{
}
public void printNode(int position)
{
Node<E> temp,temp1;
for(int i=0,temp=tail;i<position;i--)
{
temp=temp.next;
flag=0;}
if(flag)
System.out.println( "String is : " + temp.data );
System.out.println( "String is : " + temp.data );
}
}
public void printAllNodes()
{
for(int i=0,temp=tail;temp.next!=null;temp=temp.next)
System.out.println( "String is : " + temp.data );
}
}
class editor
{
public static void main(String[] args) {
StringBuffer e="how to do this problem";
DoublyLinkedList<String> ob;
while(1)
{
System.out.println( "enter the choice is " );
Scanner reader = new Scanner(System.in);
char c = reader.nextChar();
switch(){
case I:ob.insert("hello");
Break;
case D:ob.deleteByPosition(2);
break;
case IA:ob.inserafter(2,"boys");
break;
case IB:ob.insertbefore(4,"girls");
break;
case l:ob.printnode(5);
break;
case Q:Break;
}
}
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
BHAVANI RAGHU
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.