Question: //---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using a linked list // of LLStringNode to hold the log strings. // ajg

 //---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface

//---------------------------------------------------------------------- // LinkedStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using a linked list // of LLStringNode to hold the log strings. // ajg version: formatting; private; while->for; if //---------------------------------------------------------------------- package ch02.stringLogs; public class LinkedStringLog implements StringLogInterface { private String name; // name of this StringLog private LLStringNode log = null ; // reference to the first node of // linked list holding the strings // Create an empty StringLog object with name "name". public LinkedStringLog(String name) { this.name = name; } public void insert(String element) { // Precondition: This StringLog is not full. LLStringNode newNode = new LLStringNode(element); newNode.setLink(log); log = newNode; } public boolean isFull() { return false; } // Return the number of Strings in this StringLog. public int size() { int count = 0; for (LLStringNode node=log; node!=null; node=node.getLink()) count++; return count; } public boolean contains(String element) { // Ignore case difference when doing string comparison. for (LLStringNode node=log; node!=null; node=node.getLink()) if (element.equalsIgnoreCase(node.getInfo())) // they match return true; return false; } public void clear() { log = null; } public String getName() { return name; } // Return a nicely formatted string representing this StringLog. public String toString() { String ans = "Log: " + name + " "; int count = 0; for (LLStringNode node=log; node!=null; node=node.getLink()) ans += (++count) + ". " + node.getInfo() + " "; return ans; } } 

For Exercises 49-50 use case-insensitive string comparisons. 49Design and code a new method to be exported from Linkedstringlog called howMny, with the following signature: public nt howMiny(St ring el ement) The method returns an int value indicating how many times el ement occurs in the StringLog. 50 Design and code a new method to be exported from LinkedStringlog called uni qInsert, with the following signature: pubc bool ean uni qInsert(St ring el ement) The method inserts element into the StringLog unless an identical string already exists in the StringLog, in which case it has no effect on the StringLog. If it does insert the string, it returns t r ue; otherwise, it returns f al se. 51. Design and code a new method to be exported from LinkedStringlog called small est, with the following signature: public String smllest () The method returns the smallest string in the StringLog. By "smallest," we mean in terms of the lexicographic ordering supported by the St ri ng class's compar eTo method. As a precondition you should assume that the StringLog is not empty

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!