1. Engineering
  2. Computer Science
  3. package hw2 a class that mimics how javas...

Question: package hw2 a class that mimics how javas...

Question details

package hw2;

/**

* A class that mimics how Java's String class behaves.

*/

public class MyString {

private char[] data;

/**

* Construcs a <code>MyString</code> object to represent the text in

* <code>string</code>

* @param string the <code>String</code> we are representing.

*/

public MyString(String string) {

// TODO

}

/**

* A lexicographical comparison of <code>this Mystring</code> to <code>other</code>.

* The comparison is case sensitive, meaning it might not return the correct answer

* if the text being compared isn't all the same case.

*

* @param other the <code>MyString<code> to compare against.

* @return a negative number if <code>this</code> appears before <code>other</code>

* in the dictionary, a positive number if <code>this</code> appears after

* <code>other</code> in the dictonary, and 0 if <code>this</code> and <code>other</code>

* represent the same <code>String</code>

*/

public int compareTo(MyString other) {

// TODO

return 0;

}

public char charAt(int i) {

// TODO

return '\0';

}

public int length() {

// TODO

return -1;

}

public int indexOf(char c) {

// TODO

return -2;

}

@Override

public boolean equals(Object obj) {

// TODO

return false;

}

}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution