When i run my String class together with the provided Main class and OS vm files
my charAt method show strange behavior.
/** Returns the character at location j. */
method char charAt(int j) {
return txt[j];
}
I get this VMEmulator output :
My problem is with the charAt[2] value 599.
The prefix 5 is related with the object field length and/or the length method.
I tried a string with 4 characters and the prefix also changed to 4.
My length method is :
/** Returns the current length of this String. */
method int length() {
return length;
}
One of the suspects is my constructor . I found a solution to the zero capacity string: only declare the array, in the charAt method referred to as txt, and let it alone.
Maybe a little bit tricky. But it got through the test. And the string in the case of this charAt test has a size of 6 anyway.
By the way there is another problem with the test of the negative integer as you can see.
I can solve that very easily with an additional dispose and new call, but i don't know
if that counts as a 'proper' solution.
I would appreciate help on these problems.
--Chrit