首页 > > 详细

辅导HOMEWORK Programming Assignment 2 -

HOMEWORK - SPRING 2022
Programming Assignment 2 - due Monday, March 28th by 7PM (China time)
Be sure your code follows the coding style for CSE214.
Make sure you read the warnings about academic dishonesty. Remember, all work you submit for homework assignments MUST be entirely your own work. Also, group efforts are not allowed.
Login to your grading account and click "Submit Assignment" to upload and submit your assignment.
You are not allowed to any other predefined Java API Data Structure classes such as LinkedList, ArrayList, Vector to implement this assignment except where noted.
You may use Scanner, InputStreamReader, or any other class that you wish for keyboard input.
A text editor is a utility program that lets a user to create, view, edit and store text files (or documents). This differs from a word processor in that the word processors often embed special control codes or escape sequences in the file to control formatting. Typically, a text editor provides special commands that allow the user to browse the text (e.g. moving forward or backward through the text), make changes in the text, save the text, and perform other actions. In line editors, such as ed on Unix or edlin on Windows, user enters commands which apply to the current line or some range of lines, and the visual feedback is restricted to display of one or more lines, in contrast to a screen editor.

In this assignment, you are required to implement a line editor with a limited set of options.

1. Write a fully-documented class named LineNode that contains a line (String), and references to two other LineNodes (denoted "previous" and "next"). Your class will follow this general specification, but you have to fill in the details:

public class LineNode

Constructor for LineNode
public LineNode()
setLine
public void setLine(String line)
getLine
public String getLine()
setNext
public void setNext(LineNode node)
setPrev
public void setPrev(LineNode node)
getNext
public LineNode getNext()
getPrev
public LineNode getPrev()
2. Write a fully-documented class named LineList that contains references to the head, tail, and cursor (current line) of a list of LineNode nodes. Your class will follow this specification, but you have to fill in the details:

public class LineList

Constructor for LineList
public LineList()
insertBeforeCursor
public boolean insertBeforeCursor(String line)
Inserts the line before the cursor. This method should not change the cursor. The boolean return value indicates whether the insertion occurred or not (if the list is empty, no insertion is made).
append
public void append(String line)
Appends the line at the end of the list, i.e. after the tail node. The cursor should be advanced to the new line, just appended.
removeCursor
public boolean removeCursor()
Removes the cursor node, if any. The boolean return value indicates whether the removal occurred or not.
nextLine
public String nextLine()
Returns the line after cursor and advances cursor to next node. If cursor is referring to the tail node, return null.
previousLine
public String previousLine()
Returns the line before cursor and moves cursor to previous node. If cursor is referring to head node, return null.
cursorLineNo
public int cursorLineNo()
Returns the position of the cursor in the list, where head node is in position one. If cursor is null (list is empty), return zero.
NOTE: Do not destroy the list as you do this.
printCursor
public void printCursor()
Prints the line in cursor node, preceded by its line number.
printList
public LineNode printList(int startingLine, int endingLine)
Prints the list from startingLine to endingLine, one node per line, where startingLine and endingLine are positions of respective nodes in the list (head node is in position one). In the output, each line must be preceded by its position (i.e. the line number). If startingLine is greater than endingLine, or if it doesn't exist, you must throw an exception to the calling program. If endingLine exceeds number of nodes in the list, simply stop at the tail node. This method must set cursor to the reference of the last line printed and return the same reference as result.
NOTE: Do not destroy the list as you do this.
3. Write a fully-documented class named Editor. This class will contain a main method that receives a sequence of options from the keyboard and performs necessary action after each option is entered. Following is the list of valid options and required values, along with what to do if the user enters that option.

A
Appends one or more lines at the end of text. Prompt the user for the lines, one at the time, and append it to the end of text after each line is entered. Also, set the current line to the last line appended.
H
Helps the user by displaying all valid options.
I
Inserts one or more lines before the current line. You must prompt the user for the lines, one at the time, and after the user enters a string, insert it before the current line. The current line is not changed.
L
Prints one or more lines of the text, from startingLine to endingLine, and each line is preceded by its line number. If startingLine is greater than endingLine, or if it doesn't exist, print an approapriate message and ignore the entry. If endingLine exceeds number of lines in the text, simply stop at the last line of the text. The current line should be set to the last line printed. This option can also be used to move the current line to a specific position. For example "L 3 3" prints the third line and sets the current line to that line.
N
Moves forward to the next line and prints that line. If current line is at the bottom of text, prints a message and ignores the entry.
P
Moves backward to the previous line and prints that line. If current line is at the top of text, prints a message and ignores the entry.
R
Removes the current line, if there's at least one line in the text, otherwise prints a message and ignores the entry.
Q
If the text is modified or a new line is inserted, quit the program after user's confirmation; otherwise quit without a confirmation.

4. Supply any exception handling class(es) that you need in addition to the classes above.

Note: You may include additional methods, if necessary.
INPUT FORMAT


Each option and its required values are entered on one line and they are separated by at least one blank. The options are NOT case sensitive. For example n and N are the same.
If an invalid option is entered, print a message and ignore the entry.
If the user does not enter all required values on the line, print a message and ignore the entry.
If the user enters more than required values on the line, process the required values and ignore the extra values.
You may assume that the entries are of the correct type, but you have to check the range if applicable. For example if you're expecting to receive a line number, you may assume that an integer will be entered. However you must test to make sure this is a valid line number.
Our test cases will not include lines longer than 60 characters.
SAMPLE EDITING SESSION

Notes:
1. Prompts and other program outputs are shown in blue (the rest are user input).
2. Your output and prompts can vary in style (line numbers must be included).


CSE214 Editor, Version 1.0, 03/11/22
> h
A Append one or more lines at the end of file.
I Insert one or more lines before the current line.
H Help.
L List one or more lines.
P Move to the previous line.
N Move to the next line.
Q Quit.
R Remove the current line.
> a 5
1*public void addAll(IntArrayBag addend) {
2* ensureCapacity(manyItems + addend.manyItems);
3* // I didn't enter the for loop. It's okay I'll add it later.
4* add(addend.data[i]);
5*}
> L 3 3
3* // I didn't enter the for loop. It's okay I'll add it later.
> r
> I 1
3* for(int i=0; i < addend.manyItems; i++)
> L 1 99
1*public void addAll(IntArrayBag addend) {
2* ensureCapacity(manyItems + addend.manyItems);
3* for(int i=0; i < addend.manyItems; i++)
4* add(addend.data[i]);
5*}
> L 1 1
1*public void addAll(IntArrayBag addend) {
> P
** Top of file reached **
> i 3
1* //
2* // This method doesn't work correctly if addend is the same as this IntArrayBag.
3* //
> L 9 1
** Invalid Line Range **
> L 1 99 // extra values must be ignored
1*//
2*// This method doesn't work correctly if addend is the same as this IntArrayBag.
3*//
4*public void addAll(IntArrayBag addend) {
5* ensureCapacity(manyItems + addend.manyItems);
6* for(int i=0; i < addend.manyItems; i++)
7* add(addend.data[i]);
8*}
> N
** End of file reached **
> p
7* add(addend.data[i]);
> p ignore this ....
6* for(int i=0; i < addend.manyItems; i++)
> n
7* add(addend.data[i]);
> T
** Invalid Option **
> q
Are you sure? y
Good Bye.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!