Java Reference
In-Depth Information
**10.23
(
Implement the
String
class
) The
String
class is provided in the Java library.
Provide your own implementation for the following methods (name the new
class
MyString2
):
public
MyString2(String s);
public int
compare(String s);
public
MyString2 substring(
int
begin);
public
MyString2 toUpperCase();
public char
[] toChars();
public static
MyString2 valueOf(
boolean
b);
10.24
(
Implement the
Character
class
) The
Character
class is provided in the Java
library. Provide your own implementation for this class. Name the new class
MyCharacter
.
**10.25
(
New string
split
method
) The
split
method in the
String
class returns an
array of strings consisting of the substrings split by the delimiters. However, the
delimiters are not returned. Implement the following new method that returns
an array of strings consisting of the substrings split by the matching delimiters,
including the matching delimiters.
public static
String[] split(String s, String regex)
For example,
split("ab#12#453", "#")
returns
ab
,
#
,
12
,
#
,
453
in an
array of
String
, and
split("a?b?gf#e", "[?#]")
returns
a
,
b
,
?
,
b
,
gf
,
#
, and
e
in an array of
String
.
*10.26
(
Calculator
) Revise Listing 7.9, Calculator.java, to accept an expression as
a string in which the operands and operator are separated by zero or more
spaces. For example,
3+4
and
3 + 4
are acceptable expressions. Here is a
sample run:
**10.27
(
Implement the
StringBuilder
class
) The
StringBuilder
class is provided
in the Java library. Provide your own implementation for the following methods
(name the new class
MyStringBuilder1
):
public
MyStringBuilder1(String s);
public
MyStringBuilder1 append(MyStringBuilder1 s);
public
MyStringBuilder1 append(
int
i);
public int
length();
public char
charAt(
int
index);
public
MyStringBuilder1 toLowerCase();
public
MyStringBuilder1 substring(
int
begin,
int
end);
public
String toString();
Search WWH ::
Custom Search