218k views
2 votes
Your program will be a line editor. A line editor is an editor where all operations are performed by entering commands at the command line. Commands include displaying lines, inserting text, editing lines, cutting and pasting text, loading and saving files. For example, a session where the user enters three lines of text and saves them as a new file may appear as:

1 Answer

4 votes

Answer:

Java program given below

Step-by-step explanation:

import java.util.*;

import java.io.*;

public class Lineeditor

{

private static Node head;

class Node

{

int data;

Node next;

public Node()

{data = 0; next = null;}

public Node(int x, Node n)

{data = x; next =n;}

}

public void Displaylist(Node q)

{if (q != null)

{

System.out.println(q.data);

Displaylist(q.next);

}

}

public void Buildlist()

{Node q = new Node(0,null);

head = q;

String oneLine;

try{BufferedReader indata = new

BufferedReader(new InputStreamReader(System.in)); // read data from terminals

System.out.println("Please enter a command or a line of text: ");

oneLine = indata.readLine(); // always need the following two lines to read data

head.data = Integer.parseInt(oneLine);

for (int i=1; i<=head.data; i++)

{System.out.println("Please enter another command or a new line of text:");

oneLine = indata.readLine();

int num = Integer.parseInt(oneLine);

Node p = new Node(num,null);

q.next = p;

q = p;}

}catch(Exception e)

{ System.out.println("Error --" + e.toString());}

}

public static void main(String[] args)

{Lineeditor mylist = new Lineeditor();

mylist.Buildlist();

mylist.Displaylist(head);

}

}

User Divyesh Savaliya
by
6.1k points