Question: I have a Document class implemented in Java below which is made up of one String instance for the title and a String linked list

I have a "Document" class implemented in Java below which is made up of one String instance for the title and a String linked list to represent the content of documents. There is an instance in each node of the content list variable that represents the line number in the list. I need to implement a method that replaces the content on a given line number with the new string given. My code so far can be found below:

public class Node { private String data; private Node next; private int lineNum; public Node(String data, Node next, int lineNum) { this.data = data; this.next = next; this.lineNum = lineNum; } public Node(String data, Node next) { this.data = data; this.next = next; } public void print() { System.out.println(lineNum+ " " +data); if (next != null) next.print(); } public String getData() { return data; } public Node getNext() { return next; }
public int getLineNum() { return lineNum; } }
public class List { private Node head; public List() { head = null; } public void print() { if (head != null) { head.print(); } } public void add ( String data ) { if (isEmpty()) head = new Node(data, head,0); else{ int count = head.getLineNum() + 1; head = new Node(data,head,count); } } /*public void add ( String data ) { head = new Node(data, head); }*/ public boolean find(String key) { Node current = head; //Initialize current while (current != null) { if (current.getData().equals(key)) return true; //data found current = current.getNext(); } return false; } public boolean isEmpty(){ return head == null; } 
public class List { private Node head; public List() { head = null; } public void print() { if (head != null) { head.print(); } } public void add ( String data ) { if (isEmpty()) head = new Node(data, head,0); else{ int count = head.getLineNum() + 1; head = new Node(data,head,count); } } /*public void add ( String data ) { head = new Node(data, head); }*/ public boolean find(String key) { Node current = head; //Initialize current while (current != null) { if (current.getData().equals(key)) return true; //data found current = current.getNext(); } return false; } public boolean isEmpty(){ return head == null; } 
public class Document { private String title; private List content; public Document(String title){ if (title.length()<80) { this.title = title; content = new List(); } } public void addDocument(String line){ if (!content.find(line)){ content.add(line); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!