CS 1103-01 Assignment Unit 3
CS 1103-01 Assignment Unit 3
Java
public Tape() {
// Create a new cell with a blank space and set the current cell pointer to it.
currentCell = cell;
return currentCell;
return currentCell.content;
}
public void setContent(char ch) {
currentCell.content = ch;
if (currentCell.prev == null) {
newCell.next = currentCell;
currentCell.prev = newCell;
currentCell = newCell;
} else {
currentCell = currentCell.prev;
if (currentCell.next == null) {
// Create a new cell to the right of the current cell.
newCell.prev = currentCell;
currentCell.next = newCell;
} else {
currentCell = currentCell.next;
// Create a temporary pointer to move along the tape without changing the current cell
pointer.
tempCell = tempCell.next;
}
// Append the contents of each cell to the string builder.
sb.append(tempCell.content);
tempCell = tempCell.next;
return sb.toString().trim();
This code implements all of the required methods for the Tape class. The constructor creates a
new tape with a single cell containing a blank space. The other methods allow the user to
access the current cell, change its content, move the current cell left or right, and get the