Lab 5

due: Monday March 31 at 11:59pm (submit on Gradescope here).

Goals:

In this lab, you'll use a doubly-linked list of characters to represent the lines of text in your own text editor called MiddDocs.

As in Lab 4, you'll work in groups. Recall that only one group member should start the Live Share server (by clicking on Live Share). Then send this link to the other group member(s). Please work in pairs. If necessary, you can form a group of 3 but no higher than this please (this limit has been set in Gradescope).

Complete the Line class.

You do not need to change any of the code in TextEditor.java, but feel free to investigate if you're curious about certain things! The only file you need to change, and upload to Gradescope is the Line.java file. The starter code can be downloaded here.

Line.java contains two class definitions: CharacterNode and Line. The CharacterNode class represents a character in a line of text, which is designed as a node in a doubly-linked list. Hence, it has prev and next fields (which are public). It also stores the character (private), which is like the data field we used in our examples in class.

The Line class is a doubly-linked list which keeps track of the head and cursor nodes. The head is the first character in the line (if any) and the cursor is the current location of the cursor, which can be moved with the arrow keys. There is no tail in the Line linked list. All operations (insertion, deletion, cursor movement) operate on the current location of the cursor node. When the cursor is drawn (as a vertical bar |), it is drawn immediately after the character where the cursor is located. For example, the sequence of characters abcd|efgh means the cursor is at the letter d (and the head is at the letter a).

Important note: in order to represent the cursor being at the beginning of a line, the cursor can be null (while the head is non-null). For example, the line |abcd means the cursor is null, and the head is a.

Your task is to complete 5 methods, which we suggest implementing in the following order. Make sure to check and update the next and prev fields (as necessary).

A PSVM has been set up for you to get started testing these methods. Please use this to develop your Line class. You can then test the fully-featured MiddDocs editor by running TextEditor.java.

You can use the Escape key to exit MiddDocs. You'll then be prompted (in the command-line) about saving the file: respond with either y (yes) or n (no). If you save the file, you can then re-open it directly from the command-line, which will require compiling your code separately with javac and then running it with java. For example if you write a poem and save it to poem.txt:

$ javac TextEditor.java
$ java TextEditor poem.txt

Submission

Upload Line.java to Gradescope. Since you worked on the code as a group, you can submit as a group or you can submit individually if you prefer. Remember to check the style of your code and remember to include name(s) at the top of the file!