Answered step by step
Verified Expert Solution
Link Copied!

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 16 characters.
Initialize capacity to 16
Initialize length to 0
Initialize data to a new char array of size equal to capacity
MyString(capacity : 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 16.
Initialize capacity to either 16 or the value of the argument (whichever is larger)
Initialize length to 0
Initialize data to a new char array of size equal to the capacity
MyString(text : 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 16 or the length of the String argument(whichever 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
charAt(index : int) : char Returns the char in this MyString instance that is at the index specified by the argument.
If the parameter is less than 0 or greater than or equal to the length, then this method should throw a StringIndexOutOfBoundsException
concat(text : 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, e.g. given a MyString named s1 that stores "sand" and a MyString named s2 that stores " and bananas", the call s1.concat(s2) should result in s1 storing "sand and bananas"
equals(text : 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
indexOf(text : MyString) : int Returns the zero-based index where the argument MyString can first be found (from left to right) in this MyString instance.
Example: Given a MyString named s1 that stores "sand and bananas" and a MyString named s2 that stores "and", the call s1.indexOf(s2) should return 1 because the character sequence "and" is first found starting at index 1 in the MyString named s1.
If the argument MyString is not found in this MyString instance, then this method should return -1
length() : int Accessor method that should return the value currently stored in the length instance variable.
makeCapacity(capacity : 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
store(text : String) Stores a copy of the sequence of characters in the argument String in this MyString instance
store(text : MyString) Stores a copy of the sequence of characters in the argument MyString in this MyString instance
substring(start : 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 0 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, i.e. 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data With Hadoop MapReduce A Classroom Approach

Authors: Rathinaraja Jeyaraj ,Ganeshkumar Pugalendhi ,Anand Paul

1st Edition

1774634848, 978-1774634844

More Books

Students also viewed these Databases questions