Question: 1-Edit the following class ArrayStringLog in to jGraspe Save it as E:ArrayStringLog.java then compile that file in jGraspe then you will see in your drive
1-Edit the following class ArrayStringLog in to jGraspe Save it as E:\ArrayStringLog.java then compile that file in jGraspe then you will see in your drive a file: E:\ArrayStringLog.class public class ArrayStringLog { 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) // 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) // Ignores case differences when doing string comparison. { int location = 0; while (location <= lastIndex) { if (element.equalsIgnoreCase(log[location])) // if they match return true; else location++; } return false; } public void clear() // Makes this StringLog empty. { for (int i = 0; i <= lastIndex; i++) log[i] = null; lastIndex = -1; } public String getName() // Returns the name of this StringLog. { return name; } public String toString() // Returns a nicely formatted string representing this StringLog. { String logString = "Log: " + name + " "; for (int i = 0; i <= lastIndex; i++) logString = logString + (i+1) + ". " + log[i] + " "; return logString; } } 2-Edit the following code then save it as E:\ UseStringLog.java Compile then fix errors Then run the program then have screen shot. public class UseStringLog { public static void main(String[] args) { ArrayStringLog sample; sample = new ArrayStringLog("Example Use"); sample.insert("Elvis"); sample.insert("King Louis XII"); sample.insert("Captain Kirk"); System.out.println(sample); System.out.println("The size of the log is "+sample.size()); System.out.println("Elvis is in the log: "+sample.contains("Elvis")); System.out.println("Santa is in the log: "+sample.contains("Santa")); } } Sample of running Log: Example Use 1. Elvis 2. King Louis XII 3. Captain Kirk The size of the log is 3 Elvis is in the log: true Santa is in the log: false Your Assignment is to add more methods: sample.isFull() sample.insert(Soliman) sample.size() sample.toString()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
