I need a program written in Java. Write a simple line editor. Keep the entire te
ID: 3801274 • Letter: I
Question
I need a program written in Java.
Write a simple line editor. Keep the entire text in an ArrayList object, one line in a separate index position. Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number n following it, then insert the text to be followed on line n. If I is not followed by a number, then insert the text on the current line. If D is entered with two numbers n and m,one n, or no number then delete lines n through m, line n, or the current line. Do the same with command L, which stands for listing lines. If A is entered, then append the text to the existing lines or the last line. Entry E signifies exit and saving a text file.
Example:
Input file: textin.txt
The first line
And another line
EDIT testin
1>The first line
2>
3> And another line
4> I 3
3> The second line
4> One more line
5> L
1>The first line
2>
3> The second line
4> One more line
5> And another line // This is now line 5, not 3
5> D 2 // line 5, since L was issued form line 5
4> L // line 4, since one line was deleted
1>The first line
2> The second line
3> One more line
4> And another line
5>D 2 4
4>L
1>The first line
2>A
1> not done yet
2> L
1>The first line not done yet
2> E
Output File: textout.txt
The first line not done yet // the line that are left or changed after entering E must be saved in new text file. textout.txt
Explanation / Answer
import java.awt.io.*;
import java.util.*;
import java .io.*;
public class Node
{
String data;
Node node();
public Node()
{
dat=" " ;
next =null;
}
public Node(String x,Node n)
{
data=x;
next=n;
}
}
public void BuildList()
{
int Line_no=1;
Node q=new Node(" ",null);
head=q;
String oneLine;
try
{
BufferedReader indata=new BufferedReader( new inputStreamReader(system.in));
System.out.println("select your choice");
system.out.println("$insert");
system.out.println("$delet");
system.out.println("Line");
system.out.println("done");
oneLine=indata.readLine();
int x=0;
while(!oneLine.equals($done"));
{
string[] array=oneLine.split(" ");
if(array[0].equals($insert"))
{
while(!oneLine.equals("$"))
{
String line_no=String.valueOf(line_no);
Node p=new Node(line_no + " "+oneline,null);
q.next=p;
q=p;
line_no ++;
x++;
oneLine=indata.readLine();
}
}
else if(array[0].equals($delet"))
{
q=head.text;
Node z=new Node(q.data,q);
for(int i=;i<x;i++)
{
String [ ] line=q.data.split(" ");
int lower_bound=Interger.ParseInt(array[1]);
int lower_bound 2=Integer.ParseInt(line[1]);
if(lower_bound==(lower_bound_2 +1))
{
z=q;
break;
}
else
{
q=q.next;
}
}
for(int i=1;i<x;i++)
{
string [ ] line=q.data.split(" ");
if(line[0].equals(array[2]))
{
z.next=q.next;
break;
}
else
{
q=q.next;}
}
}
else if(array[0].equals("$print"))
{
q=head.next;
if(arrry.length>1)
{
int lower_bound=Interger.ParseInt(array[1]));
int upper_bound=Interger.ParseInt(array[2]));
for(int i=1;i<=x;i++)
{
String[ ] Line =q.data.split(" ");
if(line[0].equals(array[1]))
{
while(lower_bound<=upper_bound)
{
System.out.println(q.data);
q=q.next;
lower_bound++;
}
break;
}
else
{
q=q.next;
}
}
}
else
{
while(q!=null)
{
System.out.println(q.data);
q=q.next;
}
}
}
else if(oneline.equals("$line"))
{
system.out.println("its working correctly");
}
catch(Exception e)
{
System.out.println("Error"+e..toString());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.