Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please code this in Java 8 Task A ninja word is a word which hides in a sentence: it will appear continuously, but must be

please code this in Java 8 image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Task A ninja word is a word which hides in a sentence: it will appear continuously, but must be broken up by one or more spaces. For example, the word "star" is a ninja word in the phrase "best artist", but is NOT a ninja word in the phrase "twinkle twinkle little star". (Ninja words must be hidden, and thus always contain spaces). Ninja words and the sentences they appear in will always be case-insensitive. In addition, sentences may contain ninja stars (denoted with an asterisk "*"). Ninja stars can be any character, including a space. Given a list of possible ninja words, and a target sentence, return the score of the ninja words that appear in the sentence, according to the rules below. Inputs targetWords: A list of possible ninja words - e.g., ["Sun", "Moon", "Star", "Planet"] sentence: A target sentence which may contain ninja words - Sentences will contain ASCII characters Aa-Zz, spaces, and asterisks - e.g., "All the stars under the sky twinkle in slo mo on a clear night" Output Determine the score of the uncovered ninja words according to the following rules: - 1 point for every ninja word found - 1 additional point for each ninja star contained in the word "nin ja" 1 point - Each ninja word should only be counted once per sentence. If a ninja word appears multiple times, only count the instance which gives the most points Example 1 - targetWords: ["Sun", "Moon", "Star", "Planet"] - sentencer.'All the stars under the sky twinkle in slo mo on a clear night" - Analysis: The target sentence contains 2 ninja words: - "Sun", in "stars under" - "Moon", in "slo mo on" - The word "Star" is in the sentence, but it is NOT a ninja word, because it is not split up by a space. - Each ninja word is worth 1 point for a total of 2. - Return 2 - targetWords: ["Water", "Sea", "Beach", "Lake", "Shells"] - sentence.-'She sells she* 'ls on the shore for two sand dollar* each" - Analysis: The first ninja star lets us find the word "shells", when we replace " " with a space. The second ninja star allows us to find 2 additional ninja words. If we replace the * with an "s", "dollars each" contains "sea". If we replace th * with a "b", "dollarb each" contains "beach". - Each ninja word we've found has exactly one star in it, meaning each word is worth 2 points, for a total of 6 points. - Found words: She*llsSheIls>"Shells"Dollar*eachDollarbeach>"Beach"Dollar*eachDollarseach"Sea" - Return 6 * Complete the 'countNinjaWords' function below. * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. STRING_ARRAY targetWords * 2. STRING sentence / public static int countNinjaWords(List targetwords, string sentence) \{ \} \} 32> public class Solution f

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions

Question

=+Will the use of humor make the source more persuasive?

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago