Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Provided is the instructions for the class MyString and the UML diagram for the code. Please complete all of the methods. - - - -
Provided is the instructions for the class MyString and the UML diagram for the code. Please complete all of the methods.
MyString Default constructor
Initializes a new empty MyString with the capacity to store a sequence of up to characters.
Initialize capacity to
Initialize length to
Initialize data to a new char array of size equal to capacity
MyStringcapacity : int Overloaded constructor
Initializes a new empty MyString, with a capacity to store a sequence of up to the number of characters specified by the int argument.
The capacity must be a minimum of
Initialize capacity to either or the value of the argument whichever is larger
Initialize length to
Initialize data to a new char array of size equal to the capacity
MyStringtext : String Overloaded constructor
Initializes a new MyString that stores a copy of the sequence of characters in the argument String.
Initialize the capacity to either or the length of the String argumentwhichever is larger
Initialize the length to the length of the argument String
Initialize data to a new char array of size equal to capacity
Copy the sequence of characters in the argument String, into the data array
charAtindex : int : char Returns the char in this MyString instance that is at the index specified by the argument.
If the parameter is less than or greater than or equal to the length, then this method should throw a StringIndexOutOfBoundsException
concattext : MyString Appends the characters stored in the argument MyString to this MyString instance.
Note: The capacity of this MyString instance may need to be increased before the additional characters are appended, eg given a MyString named s that stores "sand" and a MyString named s that stores and bananas", the call sconcats should result in s storing "sand and bananas"
equalstext : MyString : boolean Returns true if the sequence of characters currently stored in this MyString instance and the argument MyString are identical, otherwise it returns false
indexOftext : MyString : int Returns the zerobased index where the argument MyString can first be found from left to right in this MyString instance.
Example: Given a MyString named s that stores "sand and bananas" and a MyString named s that stores "and", the call sindexOfs should return because the character sequence "and" is first found starting at index in the MyString named s
If the argument MyString is not found in this MyString instance, then this method should return
length : int Accessor method that should return the value currently stored in the length instance variable.
makeCapacitycapacity : int Changes the storage capacity of this MyString instance.
If the parameter value is less than the length of this MyString or equal to the current capacity, then this method should do nothing.
Otherwise:
This method should create a new char array that has a size equal to the argument
All characters currently stored in the data array must be copied to the same index in the new array
The new array should be stored in the data instance variable
The capacity should be updated
storetext : String Stores a copy of the sequence of characters in the argument String in this MyString instance
storetext : MyString Stores a copy of the sequence of characters in the argument MyString in this MyString instance
substringstart : int, end : int : MyString Returns a new MyString with the sequence of characters in this MyString starting at the index specified by the first argument inclusive and ending just before the index specified by the second argument exclusive
Should throw a StringIndexOutOfBoundsException if:
The first argument is less than or greater than or equal to the length of this MyString
The second argument is less than the first argument or greater than the length of this MyString, ie the end index can be equal to the length
toString : String Constructs and returns a String that contains a copy of the sequence of characters currently stored in this MyString instance. This method will override the toString method of the implicit Object super class.
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