Answered step by step
Verified Expert Solution
Question
1 Approved Answer
//---------------------------------------------------------------------- // ArrayStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using an array to hold the strings. //---------------------------------------------------------------------- public class ArrayStringLog implements StringLogInterface {
//---------------------------------------------------------------------- // ArrayStringLog.java by Dale/Joyce/Weems Chapter 2 // // Implements StringLogInterface using an array to hold the strings. //---------------------------------------------------------------------- public class ArrayStringLog implements StringLogInterface { protected String name; // name of this StringLog protected String[] log; // array that holds strings protected int lastIndex = -1; // index of last string in array public ArrayStringLog(String name, int maxSize) // Precondition: maxSize > 0 // // Instantiates and returns a reference to an empty ArrayStringLog // object with name "name" and room for maxSize strings. { log = new String[maxSize]; this.name = name; } public ArrayStringLog(String name) // Instantiates and returns a reference to an empty ArrayStringLog // object with name "name" and room for 100 strings. { log = new String[100]; this.name = name; } public void insert(String element) // Precondition: This StringLog is not full. // // Places element into this StringLog. { lastIndex++; log[lastIndex] = element; } public boolean isFull() // Returns true if this StringLog is full, otherwise returns false. { if (lastIndex == (log.length - 1)) return true; else return false; } public int size() // Returns the number of Strings in this StringLog. { return (lastIndex + 1); } public boolean contains(String element) // Returns true if element is in this StringLog, // otherwise returns false. // Ignores case differences when doing string comparison. { int location = 0; while (location 22. Design and code a new method to be exported from ArraySt ri ngLog called howMMny, with the following signature: public int howMMny(String element) The method returns an i nt value indicating how many times element occurs in the StringLog. 23. Design and code a new method to be exported from Arr aySt ri ngLog called uni qInsert, with the following signature: public bool ean u The method inserts el ement 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 rue; otherwise, it returns false ni qIns ert (String element)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started