Question: For this pre-lab work, you will implement just the structure (and not the behavior) of a custom class. This custom class will eventually have behavior
For this pre-lab work, you will implement just the structure (and not the behavior) of a custom class. This custom class will eventually have behavior similar to the Java String class. Like the Java String class, your MyString will store a sequence of characters in an array of char (char[]). Your custom MyStyring will support common string operations like concatenation, charAt, indexOf, substring, etc.
In a file named MyString.java, implement the class structure described below.
Initialize all instance variables to the default value for their data type. All void methods should have empty bodies. All methods with a return type other than void should contain a single statement that returns the default value for the return type. The default value for all numeric types and char is 0 (zero). The default value for a boolean is false. The default value for all non-primitive types is null.
MyString UML Class Diagram

Structure of the MyString Class
The MyString class must have the following private instance variables (fields):
- a variable named
capacitythat will store anint - a variable named
lengththat will store anint - a variable named
datathat will store achar[](char array)
The MyString class must have the following public constructor methods:
- a default constructor
- an overloaded constructor with an
intparameter - an overloaded constructor with a
Stringparameter
The MyString class must have the following public methods:
- a method named
charAt. This method will have one parameter of typeint. This method will return achar. - a method named
concat. This method will have one parameter of typeMyString. This method will return nothing. - a method named
equals. This method will have one parameter of typeMyString. This method will return aboolean. - a method named
indexOf. This method will have one parameter of typeMyString. This method will return anint. - a method named
length. This method will have no parameters. This method will return anint. - a method named
makeCapacity. This method will have one parameter of typeint. This method will return nothing. - a method named
store. This method will have one parameter of typeMyString. this method will return nothing. - a method named
store. This method will have one parameter of typeString. this method will return nothing. - a method named
substring. This method will have two parameters of typeint. This method will return aMyString. - a method named
toString. This method will have no parameters.
- capacity: int - length: int - data: char[] + MyString() MyString + MyString(capacity : int) + MyString(text: String) + chatAt(index: int) : char + concat(text: MyString) + equals(text: MyString): boolean +indexOf(text: MyString): int + length(): int + makeCapacity(capacity: int) + store(text: String) + store(text: MyString) + substring(start: int, end: int): MyString + toString() String - capacity: int - length: int - data: char[] + MyString() MyString + MyString(capacity : int) + MyString(text: String) + chatAt(index: int) : char + concat(text: MyString) + equals(text: MyString): boolean +indexOf(text: MyString): int + length(): int + makeCapacity(capacity: int) + store(text: String) + store(text: MyString) + substring(start: int, end: int): MyString + toString() String
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
