Question: will implement your OWN version of the String class and some of its methods. The class has the following design: public MyString( String original) :
will implement your OWN version of the String class and some of its methods. The class has the following design:

public MyString( String original) : this is the constructor for your class, it takes as input an instance of a Java String and breaks it into a character array. (See the method toCharArray in Javas class String)
public int length() - This method returns the length, or number of characters in the string
public char charAt(int index) -- given a valid index this method returns the character at that index. If an invalid index is given your method should throw an IndexOutOfBoundsException, in the form
throw new IndexOutOfBoundsException(Message); where message is the text you want printed with the exception
public MyString concat(MyString otherString) -- Concatenates the specified string, otherString, to the end of this string object producing a new MyString.
public boolean endsWith( MyString suffix) -- this method returns true if the test string ends with the specified suffix
public int indexOf( char ch) -- Returns the index within this string of the first occurrence of the specified character ch , if ch is not present in the string the method returns -1
public int indexOf( MyString str) -- Returns the index within this string of the first occurrence of the specified substring. If the substring is not present -1 is returned
public int indexOf( char ch, int fromIndex) -- Returns the index within this string of the first occurrence of the specified character, ch, starting the search at the specified index. ch is not present in the string the method returns -1
public MyString replace( char target, char replacement) -- Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
public MyString substring( int beginIndex) -- Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.
public MyString substring( int beginIndex, int endIndex) -- Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.
public MyString toUpperCase() -- Converts all of the characters in this String to upper case public MyString toLowerCase() -- Converts all of the characters in this String to lower case public String toString() -- Returns a String containing the contents of the MyString object
MyString theString: char[l + MyString( String original) + length(): int charAtlint index): char endsWith( MyString suffix): boolean + indexOf( char ch): int +indexof( MyString str) int + indexOf( char ch, int fromlndex): int +replace( char target, char replacement): MyString + substring( int beginlndex): MyString + substring( endindex): MyString + toUpperCase): MyString +toLowerCase(): MyString +toString(): String int beginindex, int
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
