Question
Line oriented editor in java. It repeatedly prompts the user for a command, executes that command on its internal file (the List of String s),
Line oriented editor in java.
It repeatedly prompts the user for a command, executes that command on its internal "file" (the List of Strings), then shows you the (line-numbered) contents of the file.
The prompt for the command shows the current line number and the number of lines in the file.
The file's lines are numbered from 1, even tho' the List stores them starting at position 0. The "current line" will be a number from 0 to the length of the List. Line 0 represents the beginning of the file. The line number should never be allowed to go outside its proper range.
The program has the following commands:
+: go to next line
-: go to the previous line
A: add a new line after the current line
X: erase the current line
S: substitute a new line for the current line
?: list the available commands with brief explanations
Q: quit program
Commands may be entered in either lower or upper case (so 'q' and 'Q' both quit the program). Commands may also be "strung together". For example, the command "aaa" would cause three lines to be added to the file. (The lines must appear in the file in the same order the user typed them in.)
If the user doesn't enter a command at the prompt, the program goes to the next line (as if a single + command had been entered).
If the user tries to go past either end of the file, the command is ignored. If the user tries to remove or change line 0, a "not applicable" message gets printed, and the command has no other effect. (Do not prompt for or read a new line value when the command is not applicable.)
Here is the OUTPUT:
At line 0 of 0 >>> a
New line: My first line!
---[[[START]]]---
1: My first line!
----[[[END]]]----
At line 1 of 1 >>> a
New line: My second line.
---[[[START]]]---
1: My first line!
2: My second line.
----[[[END]]]----
At line 2 of 2 >>> x
---[[[START]]]---
1: My first line!
----[[[END]]]----
At line 1 of 1 >>> a
New line: New second line.
---[[[START]]]---
1: New first line.
2: New second line.
----[[[END]]]----
At line 2 of 2 >>> aaa
New line: New third...
New line: ...fourth...
New line: ...and fifth lines.
---[[[START]]]---
1: New first line.
2: New second line.
3: New third...
4: ...fourth...
5: ...and fifth lines.
----[[[END]]]----
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started