Implement a class like String class and call it MyString (MyString.java). Define the following methods with your
own implementation in your class (i.e. MyString).
public MyString(char chars)
Allocates a new MyString instance so that it represents the sequence of characters currently contained in the character array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created MyString instance. Parameters: value - The initial value of the MyString instance
public void printMyString()
Prints this MyString instance.
public int length()
Returns the length of this MyString instance. The length is equal to the number of characters in this MyString instance. Returns: the length of the sequence of characters represented by this MyString object.
public char charAt(int index)
Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.Parameters: index - the index of the char value. Returns: the char value at the specified index of this MyString instance. The first char value is at index 0
public MyString substring(int beginIndex , int endIndex)
Returns a MyString instance that is a substring of this MyString instance. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus, the length of the substring is endIndex-beginIndex. Examples: substring(4, 8) of "hamburger" returns "urge" substring(1, 5) of "smiles"returns "mile" Parameters: beginIndex - the beginning index, inclusive. endIndex - the ending index, exclusive. Returns: the specified substring.
public MyString toLowerCase()
Converts all of the characters in this MyString instance to lower case. Returns: the MyString instance, converted to lowercase.
public boolean equals(MyString s)
Compares this MyString instance to the specified MyString instance. The result is true if and only if the argument is not null and is a MyString object that represents the same sequence of characters as this MyString object. Overrides: equals in class Object.Parameters: s - The object to compare this MyString instance against Returns: true if the given MyString object represents a MyString equivalent to this MyString instance, false otherwise
public static MyString valueOf(int i)
Returns the MyString representation of the int argument. The representation is exactly the one returned by the Integer.toString method of one argument. Parameters: i - an int. Returns: a MyString representation of the int argument.
Recently Asked Questions
- Using Command-line as the proper interface to accept four user inputs as following: Note: You will need to declare variables to store user value Enter user's
- Please explain how I can modify my program so it can only allow up to 3 incorrect inputs and then ends the program. The first screenshot is the starting
- Hi! So the first image shows the questions that I received in my class. The second image is and answer that one of my friends recommended. I understand what