Question: // CS 0445 Spring 2019 // Read this class and its comments very carefully to make sure you implement // the class properly. The data

// CS 0445 Spring 2019 // Read this class and its comments very carefully to make sure you implement // the class properly. The data and public methods in this class are identical // to those MyStringBuilder, with the exception of the two additional methods // shown at the end. You cannot change the data or add any instance // variables. However, you may (and will need to) add some private methods. // No iteration is allowed in this implementation. // For more details on the general functionality of most of these methods, // see the specifications of the similar method in the StringBuilder class. public class MyStringBuilder2 { // These are the only three instance variables you are allowed to have. // See details of CNode class below. In other words, you MAY NOT add // any additional instance variables to this class. However, you may // use any method variables that you need within individual methods. // But remember that you may NOT use any variables of any other // linked list class or of the predefined StringBuilder or // or StringBuffer class in any place in your code. You may only use the // String class where it is an argument or return type in a method. private CNode firstC; // reference to front of list. This reference is necessary // to keep track of the list private CNode lastC; // reference to last node of list. This reference is // necessary to improve the efficiency of the append() // method private int length; // number of characters in the list // You may also add any additional private methods that you need to // help with your implementation of the public methods. // Create a new MyStringBuilder2 initialized with the chars in String s public MyStringBuilder2(String s) { } // Create a new MyStringBuilder2 initialized with the chars in array s public MyStringBuilder2(char [] s) { } // Create a new empty MyStringBuilder2 public MyStringBuilder2() { } // Append MyStringBuilder2 b to the end of the current MyStringBuilder2, and // return the current MyStringBuilder2. Be careful for special cases! public MyStringBuilder2 append(MyStringBuilder2 b) { } // Append String s to the end of the current MyStringBuilder2, and return // the current MyStringBuilder2. Be careful for special cases! public MyStringBuilder2 append(String s) { } // Append char array c to the end of the current MyStringBuilder2, and // return the current MyStringBuilder2. Be careful for special cases! public MyStringBuilder2 append(char [] c) { } // Append char c to the end of the current MyStringBuilder2, and // return the current MyStringBuilder2. Be careful for special cases! public MyStringBuilder2 append(char c) { } // Return the character at location "index" in the current MyStringBuilder2. // If index is invalid, throw an IndexOutOfBoundsException. public char charAt(int index) { } // Delete the characters from index "start" to index "end" - 1 in the // current MyStringBuilder2, and return the current MyStringBuilder2. // If "start" is invalid or "end" <= "start" do nothing (just return the // MyStringBuilder2 as is). If "end" is past the end of the MyStringBuilder2, // only remove up until the end of the MyStringBuilder2. Be careful for // special cases! public MyStringBuilder2 delete(int start, int end) { } // Delete the character at location "index" from the current // MyStringBuilder2 and return the current MyStringBuilder2. If "index" is // invalid, do nothing (just return the MyStringBuilder2 as is). // Be careful for special cases! public MyStringBuilder2 deleteCharAt(int index) { } // Find and return the index within the current MyStringBuilder2 where // String str first matches a sequence of characters within the current // MyStringBuilder2. If str does not match any sequence of characters // within the current MyStringBuilder2, return -1. Think carefully about // what you need to do for this method before implementing it. public int indexOf(String str) { } // Insert String str into the current MyStringBuilder2 starting at index // "offset" and return the current MyStringBuilder2. if "offset" == // length, this is the same as append. If "offset" is invalid // do nothing. public MyStringBuilder2 insert(int offset, String str) { } // Insert character c into the current MyStringBuilder2 at index // "offset" and return the current MyStringBuilder2. If "offset" == // length, this is the same as append. If "offset" is invalid, // do nothing. public MyStringBuilder2 insert(int offset, char c) { } // Insert char array c into the current MyStringBuilder2 starting at index // index "offset" and return the current MyStringBuilder2. If "offset" is // invalid, do nothing. public MyStringBuilder2 insert(int offset, char [] c) { } // Return the length of the current MyStringBuilder2 public int length() { } // Delete the substring from "start" to "end" - 1 in the current // MyStringBuilder2, then insert String "str" into the current // MyStringBuilder2 starting at index "start", then return the current // MyStringBuilder2. If "start" is invalid or "end" <= "start", do nothing. // If "end" is past the end of the MyStringBuilder2, only delete until the // end of the MyStringBuilder2, then insert. This method should be done // as efficiently as possible. In particular, you may NOT simply call // the delete() method followed by the insert() method, since that will // require an extra traversal of the linked list. public MyStringBuilder2 replace(int start, int end, String str) { } // Reverse the characters in the current MyStringBuilder2 and then // return the current MyStringBuilder2. public MyStringBuilder2 reverse() { } // Return as a String the substring of characters from index "start" to // index "end" - 1 within the current MyStringBuilder2 public String substring(int start, int end) { } // Return the entire contents of the current MyStringBuilder2 as a String public String toString() { } // Find and return the index within the current MyStringBuilder2 where // String str LAST matches a sequence of characters within the current // MyStringBuilder2. If str does not match any sequence of characters // within the current MyStringBuilder2, return -1. Think carefully about // what you need to do for this method before implementing it. For some // help with this see the Assignment 3 specifications. public int lastIndexOf(String str) { } // Find and return an array of MyStringBuilder2, where each MyStringBuilder2 // in the return array corresponds to a part of the match of the array of // patterns in the argument. If the overall match does not succeed, return // null. For much more detail on the requirements of this method, see the // Assignment 3 specifications. public MyStringBuilder2 [] regMatch(String [] pats) { } // You must use this inner class exactly as specified below. Note that // since it is an inner class, the MyStringBuilder2 class MAY access the // data and next fields directly. private class CNode { private char data; private CNode next; public CNode(char c) { data = c; next = null; } public CNode(char c, CNode n) { data = c; next = n; } } }

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!