Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

x bffb Task 1: Longest Prefix. Write a Java program in a class named Proj2LongestPrefix that collects a single word (containing no whitespace) and then

image text in transcribed
image text in transcribed
x
bffb
Task 1: Longest Prefix. Write a Java program in a class named Proj2LongestPrefix that collects a single "word" (containing no whitespace) and then a "line" of text (which may contain whitespace), and then finds the longest prefix of the word which appears in the line. It should report the prefix and its [first] position number in the line, as shown below. If no prefix of the word appears in the line, report a message on the screen as shown below. The matches you find must be case-sensitive - same capitalization for the target word and in the line. The sample runs below show the expected output of your program for specific input values entered. The input values are displayed in bold. Be sure to check your program with not only these sample inputs, but others you devise as well. Sample Run 1: Please enter a target word: tonight Please enter a line of text: Go to the store and buy a ton of cookies. Locating longest prefix of "tonight" in the line "Go to the store and buy a ton of cookies." Longest prefix is "ton", found at position 26. Sample Run 2: Please enter a target word: tonight Sample Run 2: Please enter a target word: tonight Please enter a line of text: Go to the store and buy a TON of cookies. Locating longest prefix of "tonight" in the line "Go to the store and buy a TON of cookies." Longest prefix is "to", found at position 3. Sample Run 3: Please enter a target word: target Please enter a line of text: She barged in when it started. Locating longest prefix of "target" in the line "She barged in when it started." Longest prefix is "tar", found at position 23. Sample Run 4: Please enter a target word: put Please enter a line of text: Please shut the door. Locating longest prefix of "put" in the line "Please shut the door." No prefix found

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions