SlideShare a Scribd company logo
1 of 4
Download to read offline
Please write a code in JAVA to do line editor..
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:
The file created is:
The editor will first display a menu after which it will prompt for commands with "-> ". The
commands which can be entered can be seen in the menu appearing in the example.
This web page was written with the line editor described here.
The Commands
If you run the program with no command line arguments it will begin with an empty document.
If you give the name of an existing file as a command line argument it will open and load the
contents of that file. You can exit the program with either the quit, q, or write and quit, wq,
command.
Displaying the menu
The menu is displayed when the program starts. It can be displayed with the command m.
Reading and writing files
The load file command l will ask the user for a file name, open the file for reading, read the file
contents into the editor and close the file. If there is already text in the editor it is discarded. The
write file command w will write the contents of the editor to a file. If a file has previously been
opened with the read file command that same file is used for writing. Otherwise, the program
will prompt the user for a file name. For either the read or write file commands if the requested
file cannot be opened an appropriate error message is displayed.
Displaying text
Text can be displayed with three commands: show all (sa), show range (sr), and show line (sl).
All three commands display text with line numbers. Show all displays the entire document. Show
range will ask the user a range of lines ("from" and "to") and will display the lines in that
range. If the "to" line number is greater than the number of lines in the document lines up to the
end of the document will be displayed. Show line will ask the user for a line number and display
that line.
Entering new lines of text
New lines of text are entered using the new line command nl. Before entering a new line the
program will ask type line? (y/n). If the user chooses yes the line will be accepted after the line
number is displayed. If the document is empty the new line will be the first line (line 1) of the
document. If the document is notempty the program will prompt the user to enter the line after
which the new line will be placed. If the line number is out of range the program will not accept
a new line. A new first line can be added by asking to add a line after (the non-existent) line 0.
After the user has entered a line the program will continue asking for new lines until the user
answers no. As the new lines are being entered they are added sequentially to the document. As
the user begins to enter lines at the new line command the line after which the new line is being
added is first displayed (unless the user is entering lines at the beginning of the document).
Examples:
The buffers
There are two buffers, the line buffer and the string buffer, used for moving blocks of text. The
line buffer holds ranges of entire lines and the string buffer holds substrings of individual lines.
Whenever a new range of lines is copied to the line buffer or a string is copied to the string
buffer the previous contents of that buffer are deleted (but the other buffer is unaffected).
Moving ranges of lines
Blocks of lines can be moved using copy range, cr, and paste lines, pl. Copy range will ask the
user for a range of line numbers ("from" and "to") and will copy the lines to the line buffer -
the lines remain unchanged in the document. Paste lines will ask the user to enter the number of
the line after which the lines from the line buffer will be pasted. The lines are then copied into
the document - the line buffer is left unchanged. Ranges of lines are deleted with delete range, dr.
Again, the user is asked for the range of line numbers to delete. The lines are then deleted (the
line buffer is unchanged).
Editing a line of text
The edit line command, el will ask for the number of a line to edit then display the line preceded
by ascalewhich allows the user to identify positions in the line by number (beginning with 0).
Then the line menu is displayed and the program prompts for input.
The scale is at least as long as the line displayed. Operations chosen from the line menu will then
operate on this chosen line until quit line, q.
Show line will display the line (again) with the scale. Quit returns to the main editor menu. The
remaining commands edit the chosen line.
Copy to string buffer and Paste from string buffer work like copy range and paste lines but they
work with the string buffer rather than the line buffer. Also, Paste from string buffer will insert
the substring so that it begins at the specified position. (Thus it does an "insert before" where
paste lines does an "insert after.")
Delete substring, t, will prompt for a range of characters to delete, will display the string with the
substring underlined, ask the user if the range is ok, and then delete the substring.
Cut, t, combines copy to string buffer and delete substring. It copies the substring to the string
buffer and removes it from the line.
Enter new substring, e, will allow the user to type new text into an existing line.
Internals
You will define (among others) two classes: a Line class and a Document class. The Line class
will hold the text of a line from the document in a field of type String and provide basic
operations on a line. Some of these operations are insert a string into the line at a specified
position, delete a substring, copy a substring, etc. The Line class will also have a field with the
number of characters stored in the line. The Document class will hold an entire document (each
line in one String) and provide basic operations such as inserting lines, deleting, copying, and
pasting ranges of lines. It will also have a field with the number of lines currently in the
document. Elsewhere in your program you will provide code for the operations (chosen by the
user from the menu) which will then call the member functions of the Line and Document
classes.
The document will be a doubly linked list of lines (Strings) with a dummy node. I.e., if there are
100 lines in the document there will be 101 nodes in the linked list - 100 holding text and one
dummy node. This will make insertions and deletions much easier by eliminating special
boundary conditions. Line numbers will not be stored with lines. Instead, every time a line
number is needed (e.g. for display in show range and show all, finding positions for new line,
etc.) it will be found by traversing the list and counting.
All strings will be Java Strings. Lines of text can be manipulated with concatenation and the
substring methods:
To accept a new line of user input you must use nextLine since reading with next stops accepting
input at the first white space and text lines may contain white space. You must usenextLine for
all keyboard input: nextLine does not mix well with next, nextInt, etc., so to read integer input
you will first read a String and then convert it to an integer using Integer.parseInt.
You will do appropriate input validation. When choosing operations (in response to the "->"
prompt) your program will only accept input as stated in the menu. When accepting integer input
(line numbers, character positions in a line) your program will check for valid numbers and
ranges.
Solution
import java.io.File; // this import a package called file to perform file operations public class
MyFileOperations { public static void main(String[] a){ try{
File file = new File("fileName"); //opens the file
System.out.println(file.canRead()); //Tests whether the application can modify the
file System.out.println(file.canWrite()); //Tests whether the
application can modify the file System.out.println(file.createNewFile());
//Deletes the file or directory System.out.println(file.delete());
//Tests whether the file or directory exists. System.out.println(file.exists());
//Returns the absolute pathname string.
System.out.println(file.getAbsolutePath()); //Tests whether the file is a directory
or not. System.out.println(file.isDirectory()); //Tests whether the
file is a hidden file or not. System.out.println(file.isHidden());
//Returns an array of strings naming the //files and directories in the directory.
System.out.println(file.list()); } catch(Exception ex){
} } }

More Related Content

Similar to Please write a code in JAVA to do line editor..Your program will b.pdf

Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docxwilcockiris
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointersenidcruz
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdf
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdfInstructionYou’ll probably want to import FileReader, PrintWriter,.pdf
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdfarsmobiles
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesPrabu U
 
You are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdfYou are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdfarrowcomputers8700
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxmary772
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE jatin batra
 
Notes3
Notes3Notes3
Notes3hccit
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++Asaye Dilbo
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 

Similar to Please write a code in JAVA to do line editor..Your program will b.pdf (20)

Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Java execise
Java execiseJava execise
Java execise
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
 
String handling
String handlingString handling
String handling
 
Python for loop
Python for loopPython for loop
Python for loop
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdf
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdfInstructionYou’ll probably want to import FileReader, PrintWriter,.pdf
InstructionYou’ll probably want to import FileReader, PrintWriter,.pdf
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 
You are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdfYou are required to write an interactive C program that prompts the .pdf
You are required to write an interactive C program that prompts the .pdf
 
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docxCMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
CMPE2300 – Lab01 - Defrag-o-maticIn this lab you will crea.docx
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
Notes3
Notes3Notes3
Notes3
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
 
Ch05
Ch05Ch05
Ch05
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
LANGUAGE PROCESSOR
LANGUAGE PROCESSORLANGUAGE PROCESSOR
LANGUAGE PROCESSOR
 

More from fazilfootsteps

Why are the mass extinctions followed by a burst of speciation in .pdf
Why are the mass extinctions followed by a burst of speciation in .pdfWhy are the mass extinctions followed by a burst of speciation in .pdf
Why are the mass extinctions followed by a burst of speciation in .pdffazilfootsteps
 
Why is African American history important What challenges have Afri.pdf
Why is African American history important What challenges have Afri.pdfWhy is African American history important What challenges have Afri.pdf
Why is African American history important What challenges have Afri.pdffazilfootsteps
 
Using the phase diagram of polydstyrene and DOP below, would you ex.pdf
Using the phase diagram of polydstyrene and DOP below, would you ex.pdfUsing the phase diagram of polydstyrene and DOP below, would you ex.pdf
Using the phase diagram of polydstyrene and DOP below, would you ex.pdffazilfootsteps
 
What does it mean to say that individuals as a group are net supplier.pdf
What does it mean to say that individuals as a group are net supplier.pdfWhat does it mean to say that individuals as a group are net supplier.pdf
What does it mean to say that individuals as a group are net supplier.pdffazilfootsteps
 
True or False Statement The DNS namespace is hierarchical. Protocols.pdf
True or False Statement The DNS namespace is hierarchical. Protocols.pdfTrue or False Statement The DNS namespace is hierarchical. Protocols.pdf
True or False Statement The DNS namespace is hierarchical. Protocols.pdffazilfootsteps
 
Thoughts on this Rule by the people is the main idea behind dem.pdf
Thoughts on this Rule by the people is the main idea behind dem.pdfThoughts on this Rule by the people is the main idea behind dem.pdf
Thoughts on this Rule by the people is the main idea behind dem.pdffazilfootsteps
 
The symmetry properties of the plane figure formed by the four point.pdf
The symmetry properties of the plane figure formed by the four point.pdfThe symmetry properties of the plane figure formed by the four point.pdf
The symmetry properties of the plane figure formed by the four point.pdffazilfootsteps
 
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdf
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdfQUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdf
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdffazilfootsteps
 
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdf
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdfRobbinsdale Hospital is one of two hospitals among the six facilitie.pdf
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdffazilfootsteps
 
Research excise taxes in other states besides North Carolina. Report.pdf
Research excise taxes in other states besides North Carolina. Report.pdfResearch excise taxes in other states besides North Carolina. Report.pdf
Research excise taxes in other states besides North Carolina. Report.pdffazilfootsteps
 
Prove that E X is not connected if and only if there exist open sets.pdf
Prove that E  X is not connected if and only if there exist open sets.pdfProve that E  X is not connected if and only if there exist open sets.pdf
Prove that E X is not connected if and only if there exist open sets.pdffazilfootsteps
 
potential benefits of sustainability strategySolutionpotential.pdf
potential benefits of sustainability strategySolutionpotential.pdfpotential benefits of sustainability strategySolutionpotential.pdf
potential benefits of sustainability strategySolutionpotential.pdffazilfootsteps
 
Nessus is a network security tool- write a pragraph describe itsto.pdf
Nessus is a network security tool- write a pragraph describe itsto.pdfNessus is a network security tool- write a pragraph describe itsto.pdf
Nessus is a network security tool- write a pragraph describe itsto.pdffazilfootsteps
 
Module 01 Discussion - Dominant CultureDefine the .pdf
Module 01 Discussion - Dominant CultureDefine the .pdfModule 01 Discussion - Dominant CultureDefine the .pdf
Module 01 Discussion - Dominant CultureDefine the .pdffazilfootsteps
 
List and explain the states of process in a specific operating syste.pdf
List and explain the states of process in a specific operating syste.pdfList and explain the states of process in a specific operating syste.pdf
List and explain the states of process in a specific operating syste.pdffazilfootsteps
 
Most integer types are directly supported by hardware, but some are n.pdf
Most integer types are directly supported by hardware, but some are n.pdfMost integer types are directly supported by hardware, but some are n.pdf
Most integer types are directly supported by hardware, but some are n.pdffazilfootsteps
 
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdf
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdfIntroduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdf
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdffazilfootsteps
 
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdf
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdfIndian Institute of Management Kashipur Executive Post Graduate Pro.pdf
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdffazilfootsteps
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdffazilfootsteps
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdffazilfootsteps
 

More from fazilfootsteps (20)

Why are the mass extinctions followed by a burst of speciation in .pdf
Why are the mass extinctions followed by a burst of speciation in .pdfWhy are the mass extinctions followed by a burst of speciation in .pdf
Why are the mass extinctions followed by a burst of speciation in .pdf
 
Why is African American history important What challenges have Afri.pdf
Why is African American history important What challenges have Afri.pdfWhy is African American history important What challenges have Afri.pdf
Why is African American history important What challenges have Afri.pdf
 
Using the phase diagram of polydstyrene and DOP below, would you ex.pdf
Using the phase diagram of polydstyrene and DOP below, would you ex.pdfUsing the phase diagram of polydstyrene and DOP below, would you ex.pdf
Using the phase diagram of polydstyrene and DOP below, would you ex.pdf
 
What does it mean to say that individuals as a group are net supplier.pdf
What does it mean to say that individuals as a group are net supplier.pdfWhat does it mean to say that individuals as a group are net supplier.pdf
What does it mean to say that individuals as a group are net supplier.pdf
 
True or False Statement The DNS namespace is hierarchical. Protocols.pdf
True or False Statement The DNS namespace is hierarchical. Protocols.pdfTrue or False Statement The DNS namespace is hierarchical. Protocols.pdf
True or False Statement The DNS namespace is hierarchical. Protocols.pdf
 
Thoughts on this Rule by the people is the main idea behind dem.pdf
Thoughts on this Rule by the people is the main idea behind dem.pdfThoughts on this Rule by the people is the main idea behind dem.pdf
Thoughts on this Rule by the people is the main idea behind dem.pdf
 
The symmetry properties of the plane figure formed by the four point.pdf
The symmetry properties of the plane figure formed by the four point.pdfThe symmetry properties of the plane figure formed by the four point.pdf
The symmetry properties of the plane figure formed by the four point.pdf
 
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdf
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdfQUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdf
QUESTION 12 (Learning Outcome 3) Which of the following flawed uses o.pdf
 
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdf
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdfRobbinsdale Hospital is one of two hospitals among the six facilitie.pdf
Robbinsdale Hospital is one of two hospitals among the six facilitie.pdf
 
Research excise taxes in other states besides North Carolina. Report.pdf
Research excise taxes in other states besides North Carolina. Report.pdfResearch excise taxes in other states besides North Carolina. Report.pdf
Research excise taxes in other states besides North Carolina. Report.pdf
 
Prove that E X is not connected if and only if there exist open sets.pdf
Prove that E  X is not connected if and only if there exist open sets.pdfProve that E  X is not connected if and only if there exist open sets.pdf
Prove that E X is not connected if and only if there exist open sets.pdf
 
potential benefits of sustainability strategySolutionpotential.pdf
potential benefits of sustainability strategySolutionpotential.pdfpotential benefits of sustainability strategySolutionpotential.pdf
potential benefits of sustainability strategySolutionpotential.pdf
 
Nessus is a network security tool- write a pragraph describe itsto.pdf
Nessus is a network security tool- write a pragraph describe itsto.pdfNessus is a network security tool- write a pragraph describe itsto.pdf
Nessus is a network security tool- write a pragraph describe itsto.pdf
 
Module 01 Discussion - Dominant CultureDefine the .pdf
Module 01 Discussion - Dominant CultureDefine the .pdfModule 01 Discussion - Dominant CultureDefine the .pdf
Module 01 Discussion - Dominant CultureDefine the .pdf
 
List and explain the states of process in a specific operating syste.pdf
List and explain the states of process in a specific operating syste.pdfList and explain the states of process in a specific operating syste.pdf
List and explain the states of process in a specific operating syste.pdf
 
Most integer types are directly supported by hardware, but some are n.pdf
Most integer types are directly supported by hardware, but some are n.pdfMost integer types are directly supported by hardware, but some are n.pdf
Most integer types are directly supported by hardware, but some are n.pdf
 
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdf
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdfIntroduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdf
Introduction to Philosophy 101 HomeworkSection 3 Deductive Argum.pdf
 
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdf
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdfIndian Institute of Management Kashipur Executive Post Graduate Pro.pdf
Indian Institute of Management Kashipur Executive Post Graduate Pro.pdf
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
 
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdfIfgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
Ifgqueue.h#ifndef LFGQUEUE_H #define LFGQUEUE_H#include pl.pdf
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 

Please write a code in JAVA to do line editor..Your program will b.pdf

  • 1. Please write a code in JAVA to do line editor.. 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: The file created is: The editor will first display a menu after which it will prompt for commands with "-> ". The commands which can be entered can be seen in the menu appearing in the example. This web page was written with the line editor described here. The Commands If you run the program with no command line arguments it will begin with an empty document. If you give the name of an existing file as a command line argument it will open and load the contents of that file. You can exit the program with either the quit, q, or write and quit, wq, command. Displaying the menu The menu is displayed when the program starts. It can be displayed with the command m. Reading and writing files The load file command l will ask the user for a file name, open the file for reading, read the file contents into the editor and close the file. If there is already text in the editor it is discarded. The write file command w will write the contents of the editor to a file. If a file has previously been opened with the read file command that same file is used for writing. Otherwise, the program will prompt the user for a file name. For either the read or write file commands if the requested file cannot be opened an appropriate error message is displayed. Displaying text Text can be displayed with three commands: show all (sa), show range (sr), and show line (sl). All three commands display text with line numbers. Show all displays the entire document. Show range will ask the user a range of lines ("from" and "to") and will display the lines in that range. If the "to" line number is greater than the number of lines in the document lines up to the end of the document will be displayed. Show line will ask the user for a line number and display that line. Entering new lines of text New lines of text are entered using the new line command nl. Before entering a new line the program will ask type line? (y/n). If the user chooses yes the line will be accepted after the line number is displayed. If the document is empty the new line will be the first line (line 1) of the document. If the document is notempty the program will prompt the user to enter the line after
  • 2. which the new line will be placed. If the line number is out of range the program will not accept a new line. A new first line can be added by asking to add a line after (the non-existent) line 0. After the user has entered a line the program will continue asking for new lines until the user answers no. As the new lines are being entered they are added sequentially to the document. As the user begins to enter lines at the new line command the line after which the new line is being added is first displayed (unless the user is entering lines at the beginning of the document). Examples: The buffers There are two buffers, the line buffer and the string buffer, used for moving blocks of text. The line buffer holds ranges of entire lines and the string buffer holds substrings of individual lines. Whenever a new range of lines is copied to the line buffer or a string is copied to the string buffer the previous contents of that buffer are deleted (but the other buffer is unaffected). Moving ranges of lines Blocks of lines can be moved using copy range, cr, and paste lines, pl. Copy range will ask the user for a range of line numbers ("from" and "to") and will copy the lines to the line buffer - the lines remain unchanged in the document. Paste lines will ask the user to enter the number of the line after which the lines from the line buffer will be pasted. The lines are then copied into the document - the line buffer is left unchanged. Ranges of lines are deleted with delete range, dr. Again, the user is asked for the range of line numbers to delete. The lines are then deleted (the line buffer is unchanged). Editing a line of text The edit line command, el will ask for the number of a line to edit then display the line preceded by ascalewhich allows the user to identify positions in the line by number (beginning with 0). Then the line menu is displayed and the program prompts for input. The scale is at least as long as the line displayed. Operations chosen from the line menu will then operate on this chosen line until quit line, q. Show line will display the line (again) with the scale. Quit returns to the main editor menu. The remaining commands edit the chosen line. Copy to string buffer and Paste from string buffer work like copy range and paste lines but they work with the string buffer rather than the line buffer. Also, Paste from string buffer will insert the substring so that it begins at the specified position. (Thus it does an "insert before" where paste lines does an "insert after.") Delete substring, t, will prompt for a range of characters to delete, will display the string with the substring underlined, ask the user if the range is ok, and then delete the substring. Cut, t, combines copy to string buffer and delete substring. It copies the substring to the string buffer and removes it from the line.
  • 3. Enter new substring, e, will allow the user to type new text into an existing line. Internals You will define (among others) two classes: a Line class and a Document class. The Line class will hold the text of a line from the document in a field of type String and provide basic operations on a line. Some of these operations are insert a string into the line at a specified position, delete a substring, copy a substring, etc. The Line class will also have a field with the number of characters stored in the line. The Document class will hold an entire document (each line in one String) and provide basic operations such as inserting lines, deleting, copying, and pasting ranges of lines. It will also have a field with the number of lines currently in the document. Elsewhere in your program you will provide code for the operations (chosen by the user from the menu) which will then call the member functions of the Line and Document classes. The document will be a doubly linked list of lines (Strings) with a dummy node. I.e., if there are 100 lines in the document there will be 101 nodes in the linked list - 100 holding text and one dummy node. This will make insertions and deletions much easier by eliminating special boundary conditions. Line numbers will not be stored with lines. Instead, every time a line number is needed (e.g. for display in show range and show all, finding positions for new line, etc.) it will be found by traversing the list and counting. All strings will be Java Strings. Lines of text can be manipulated with concatenation and the substring methods: To accept a new line of user input you must use nextLine since reading with next stops accepting input at the first white space and text lines may contain white space. You must usenextLine for all keyboard input: nextLine does not mix well with next, nextInt, etc., so to read integer input you will first read a String and then convert it to an integer using Integer.parseInt. You will do appropriate input validation. When choosing operations (in response to the "->" prompt) your program will only accept input as stated in the menu. When accepting integer input (line numbers, character positions in a line) your program will check for valid numbers and ranges. Solution import java.io.File; // this import a package called file to perform file operations public class MyFileOperations { public static void main(String[] a){ try{ File file = new File("fileName"); //opens the file System.out.println(file.canRead()); //Tests whether the application can modify the file System.out.println(file.canWrite()); //Tests whether the application can modify the file System.out.println(file.createNewFile());
  • 4. //Deletes the file or directory System.out.println(file.delete()); //Tests whether the file or directory exists. System.out.println(file.exists()); //Returns the absolute pathname string. System.out.println(file.getAbsolutePath()); //Tests whether the file is a directory or not. System.out.println(file.isDirectory()); //Tests whether the file is a hidden file or not. System.out.println(file.isHidden()); //Returns an array of strings naming the //files and directories in the directory. System.out.println(file.list()); } catch(Exception ex){ } } }