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, charAtindexOfsubstring, 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

student submitted image, transcription available below

Structure of the MyString Class

The MyString class must have the following private instance variables (fields):

  • a variable named capacity that will store an int
  • a variable named length that will store an int
  • a variable named data that will store a char[] (char array)

The MyString class must have the following public constructor methods:

  • a default constructor
  • an overloaded constructor with an int parameter
  • an overloaded constructor with a String parameter

The MyString class must have the following public methods:

  • a method named charAt. This method will have one parameter of type int. This method will return a char.
  • a method named concat. This method will have one parameter of type MyString. This method will return nothing.
  • a method named equals. This method will have one parameter of type MyString. This method will return a boolean.
  • a method named indexOf. This method will have one parameter of type MyString. This method will return an int.
  • a method named length. This method will have no parameters. This method will return an int.
  • a method named makeCapacity. This method will have one parameter of type int. This method will return nothing.
  • a method named store. This method will have one parameter of type MyString. this method will return nothing.
  • a method named store. This method will have one parameter of type String. this method will return nothing.
  • a method named substring. This method will have two parameters of type int. This method will return a MyString.
  • 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

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 Programming Questions!