Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CSE 110: Principles of Programming Languages Assignment 2 Overview In this assignment you will write a program that will accept a string and a search
CSE 110: Principles of Programming Languages Assignment 2 Overview In this assignment you will write a program that will accept a string and a search term from the user. Your program will then ask the user if they want to consider spaces and if upper and lower case should be considered as different. All of these will be accepted as strings and int values will be parsed as needed. It then tells the user if the search term is in the string or not, ignoring spaces and case as asked, and where the term was in the string. Requirements Your program must do the following in order to receive full credit on this assignment. 1. Accept two string values from the user. a. The first is the original string to search through b. The second is the suhstring we will be searching the first string for, 2. Ask the user if they want to consider spaces in the two strings. a. Ask the user to type a number for Yes (I) and a second number for No (0). b. Use for yes and 0 for no, Do not use other numbers! c. This must be pulled from the Scanner as a String! 3. Ask the user if they want to consider differences between upper and lower case in the two strings a. Again, ask for a number b. Again, this must be taken in as a String. 4. Convert the two number inputs into their int values and store them in new int variables. You do not need to do any checking if they actually typed in an int or not for this assignment You can also assume that they typed in one of the numhers that you asked for a. b. If the user asked you to not consider spaces, remove them from both the original string and the search term. 5. Hint: Remember that replace allows you to replace with a blank string. a. If the user asked you to not consider case, convert both the original string and search term strings to the same case. 6. You might want to just use equalslgnoreCase, but some of the comparisons we will be making cannot ignore the case, so we must set it all to the same case in order to avoid that problem. a. 7. Make the following determinations and print the appropriate output That means that for each one of these, if it is true, print a message to tell the user what you decided. See Example Outputs for examples a. Is the scarch term equal to the entire original string? b. Is the scarch term not in the original string at all? c. Otherwise, determine which of the following is true. i. Is the search term at the beginning of the original string? ii Is the search term at the end of the original string? iii. Otherwise, prin the index that the search term starts at as well as the index it ends at. 1. For all of these, look over the methods in String. They'll help you considerably Getting the index that the search term starts at is easy, and once you know that, finding where it ends is actually not much more complicated. Make sure you think it over 2. 3. You do not need to worry about multiple occurrences of the search term. You should check these in the same order that is presented to avoid detecting the wrong thing. 4 Understand, there should only be one output from all of this Note: A lot of the time, people think they need to implement four different versions of step 7 (one for each possible combination of steps 5 and 6. This is not the case! If you have four different copies of your code you are overcomplicating things Example Inputs Below are tive example runs of the program with the inputs and outputs. Remember, the graders will be testing your program against these as well as their own, so make sure you test these and come up with your own before submitting your program. #1 Please input a word or phrase cheese is good Pleese input the string you would like to search for in your word or phrase cheese is good Do you want to consider spaces? Type 1 for Yes, or for No Do you want to consider uppercase and lowercase as different? 1 for Yes, 8 for No Your search is equal to the entire input #2 Please input a word or phrase cheese is good Please input the string you would like to scarch for in your word or phrasc foobar Do you want to consider spaces? Type 1 for Yes, or 8 for No Do you want to consider uppercase and lowercase as different? 1 for Yes, for No Your search was not found in the input #3 Plcase input a word or phrase cheese is good Pleese input the string you would like to search for in your word or phrase cheese Do you want to consider spaces? Type 1 for Yes, or B for No Do you want to consider uppercase and lowercase as different? 1 for Yes, for No Your searchst the of the beginning of the input #4 Please input a word or phrase. cheese is good Please input the string you would like to search for 1n your word or phrase isgood Do you want to consider spaces? Type 1 for Yes, or e for No Do you want to consider uppercase and lowercase as different? 1 for Yes, for No Your search is the end of the input. #5 Please 1nput a word or phrase. CHEESe IS gud Please input the string you would like to search for in your word or phrase. Sg Do you want to consider spaces? Type 1 for Yes, or for No. Do you want to consider uppercase and lowercase as different? 1 for Yes, 9 for No Your search starts at index 6 and ends at index 8 Submission Please submit your Assignment2 java file to the Assignment 2 link on Blackboard under the Assignments tab. You may submit as many times as you want prior to the due date, in case you later find and fix an error, but only the last one is graded
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started