ICS 22
Homework 2
Due 10/12
- Reminder: we check for cheating (via copying) and all students involved with get a grade of zero for this homework.
- (80 points) Write class MyString that behaves similarly to class java.lang.String. All the methods you write should behave exactly as they do for java.lang.String. You can find on-line documention at http://java.sun.com/products/jdk/1.2/docs/api. Implement all the methods listed in the start I provide at http://www.ics.uci.edu/~klefstad/s/22/src/hw2/MyString.java. Be sure your methods do not modify this MyString (same as they would behave in class java.lang.String), but rather return a new MyString when appropriate. Also, do not call String methods unless it is absolutely essential (e.g., in the constructor for a MyString that takes a String parameter - you must use length() and charAt() to extract the characters from the parameter into your array of char in this MyString. A few of the methods are not defined in String, but I want you to write them anyway. Examples are Integer.parseInt.
- (20 points) Write a single main method that tests all the functions you wrote in MyString. Test strings should be declared and intialized in your main routine and output should be sent to the console via calls to System.out.println.