Question: Add functionality using JAVA code, to the MyString class to include the methods: public boolean equals (MyString S) which indicates whether this and S are
Add functionality using JAVA code, to the MyString class to include the methods:
public boolean equals(MyString S) which indicates whether this and S are equal strings.
public void reset(MyString S) which replaces the characters in this with the characters from S
For extra credit you can demonstrate that your methods work in a "main" class by having MyStrings:
S1 = "Hello " and S2 = "Halo" and S3 = "Hello".
(Please use the simplest way to do it )
public class MyStringMain { public static void main(String[] args) { char[] MyInput = new char[50]; char[] MyInput2 = new char[50]; MyInput[0] = 'S'; MyInput[1] = 't'; MyInput[2] = 'e'; MyInput[3] = 'v'; MyInput[4] = 'e'; MyInput[5] = ' '; MyInput[6] = '#'; MyInput2[0] = 'C'; MyInput2[1] = 'o'; MyInput2[2] = 's'; MyInput2[3] = 'a'; MyInput2[4] = 'r'; MyInput2[5] = 'e'; MyInput2[6] = 's'; MyInput2[7] = '#'; MyString S1 = new MyString(MyInput); MyString S2 = new MyString(MyInput2); MyString S3 = S1.concat(S2); display(S3); } static void display(MyString S) { for(int i=0; i =========================================
public class MyString { public static final int MAXSIZE=50; public static final char DELIM = '#'; public MyString() { length=0; sArray = new char[MAXSIZE]; } public MyString(char[] inChars) { MyString(); while (inChars[length] != DELIM && length < MAXSIZE) sArray[length]=inChars[length++]; } public int getLength(){ return length; } public void appendChar(char c) { sArray[length++] = c; } public char charAt(int loc) { if (loc<0||loc>=length) return DELIM; else return sArray[loc]; } public MyString concat(MyString S) { MyString newS = new MyString(); for (int i=0; i Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
