Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Management Science The Art Of Modeling With Spreadsheets

Authors: Stephen G. Powell, Kenneth R. Baker

4th Edition

978-1118517376, 9781118800348, 1118517377, 1118800346, 978-1118582695

More Books

Students also viewed these Programming questions