Reference no: EM132206517
Write some of the methods in the Java String class API. You are not using the methods, you are writing them.
The only methods from the API you are allowed to use are:
From String class:
constructors
toCharArray( )
toString( )
From Scanner class: all methods
Name your class MyString. The fields should be the original String and an array of chars. Write a constructor method that accepts a String as a parameter and initializes the two fields.
Write a method for each of the API String methods listed above. Do not use the String API except as noted above.
Write a driver class that reads in a line of text from the user. Then test each of the methods you have written.
Be sure to print a clear explanation of the test and the results. ie: Original string is: test Result from call to toUpperCase: TEST Demonstrate the test and the result of the test
You can use the .length field that all arrays in Java have. Implement the following methods:
MyString(String str)
char charAt(int index) int compareTo(MyString anotherMyString)
int compareToIgnoreCase(MyString anotherMyString)
MyString concat(MyString str)
boolean endsWith(MyString suffix)
boolean equals(MyString anotherMyString)
boolean equalsIgnoreCase(MyString anotherMyString)
int indexOf(char ch)
int indexOf(char ch, int fromIndex)
int lastIndexOf(char ch)
int length( )
MyString replace(char oldChar, char newChar)
boolean startsWithString(MyString prefix)
MyString substring(int beginIndex)
MyString substring(int beginIndex, int endIndex)
MyString toLowerCase( )
MyString toUpperCase( )
String toString( )
For extra credit:
MyString replaceAll(MyString str, MyString replacement)
int indexOf(MyString str)
int indexOf(MyString str, int fromIndex)
boolean contains(MyString s)