Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

//---------------------------------------------------------------------- // 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions