Question: I need a little help in my programming class. Our instructor is not the greatest at teaching and is almost never available. Help is appreciated!

I need a little help in my programming class. Our instructor is not the greatest at teaching and is almost never available. Help is appreciated! =)

We are working with arrays, and this is one of our projects:

1. Create a class called MyString.

2. Make two private instance variables for MyString.

a. An int, which is the length of the String.

b. A char array, which is the characters in the String.

3. Create a default constructor for MyString which sets the length of the array to 0.

4. Create a regular constructor which takes a single String parameter and sets this MyString

object to be that String.

a. This means that the array should be as long as the parameter and each element in the array is one character from the parameter.

5. Create an boolean method called equals that accepts a String parameter and returns true if the contents of the parameter match the contents of the array.

a. This should function identically to the equals method from String.

b. Hint: Dont forget that String has a toCharArray method and a charAt method.

6. Create an int method called indexOf which takes a char argument and returns the index of the first occurrence of that char in the array.

a. Again, you do not have to worry about multiple occurrences.

b. This should return -1 if the char was not found.

7. Overload the indexOf method to create a version which takes a String parameter and returns the index of the start position of the parameter in the char array.

a. Again, return -1 if it is not in the array.

b. The whole parameter must be in the array, in order, for this to return an index.

c. Hint: For this and the upcoming steps, make sure you make use of your indexOf methods as they can save you lot of time.

8. Write a boolean method called startsWith, which accepts a String parameter and returns true if the parameter matches the beginning of the array.

9. Write a boolean method called endsWith, which accepts a String parameter and returns true if the parameter matches the end of the array.

10. Write a boolean method called contains, which accepts a String parameter and returns true if the parameter is anywhere within the array.

11. Write a String method called toString which returns a String version of all the characters in the array.

a. If there are none it should return a blank String.

b. This completes the MyString class.

12. In your main file, write a private static String method called mainMenu, which prints out the main menu and returns the users input. The menu options are as follows.

a. Create a Searchable String

b. Print the current Searchable String

c. Search within the String

d. Quit

i. This should validate the users input before returning it.

13. Write a private static void method called searchString, which accepts a MyString object as a parameter.

a. This parameter is the MyString the search will be done on.

14. Have searchString prompt the user for a String to search for and accept that from the user.

15. searchString will print out a different message for each of the following scenarios.

a. The search string is not in the MyString

b. The search is identical to the MyString

c. The MyString starts with the search string

d. The MyString ends with the search string

e. Otherwise, print the start index of the search within the MyString

i. All of these should use the methods you wrote in MyString

16. Write your main method, which will print a welcome message, run the main menu, have a loop to process inputs until the user quits, and a goodbye message after the loop exits.

17. You main method should declare and initialize a MyString object with the default constructor.

18. Inside the loop, determine which option the user typed in and do the proper action. The actions are explained in the steps below.

19. If the user chose to enter a new searchable string, prompt them for a string and then set the local MyString object to that string.

a. Remember that one of MyStrings constructors takes a String parameter.

20. If the user chose to print the current string, print out the MyString object.

21. If the user chose to search for a string, call your searchString method and pass the MyString object.

Example Inputs

#1

Hi. Welcome to the String searcher. What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String

d. Quit b

What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit a Please enter the searchable String Cake Set Cake as the searchable String What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit b Cake

What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit d Bye!

#2

Hi. Welcome to the String searcher. What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String

d. Quit a Please enter the searchable String cheese is good Set cheese is good as the searchable String What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit c What String did you want to search for? cheese is really good Search term is not in the searchable String What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit c What String did you want to search for? cheese The search is at the beginning of the string

What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit d Bye!

#3

Hi. Welcome to the String searcher. What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String

d. Quit a Please enter the searchable String aaaaa Set aaaaa as the searchable String What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit c What String did you want to search for? a The search is at the beginning of the string What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit c What String did you want to search for? aaaa The search is at the beginning of the string

What would you like to do? a. Create a Searchable String b. Print the current Searchable String c. Search within the String d. Quit d Bye!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!