For this pre-lab work, you will implement just the structure (and not the behavior) of a custom
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 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
capacity
that will store anint
- a variable named
length
that will store anint
- a variable named
data
that will store achar[]
(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 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.
Management Science The Art of Modeling with Spreadsheets
ISBN: 978-1118582695
4th edition
Authors: Stephen G. Powell, Kenneth R. Baker