Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A passage of text is rated for difficulty by the length of the words it contains. You are to complete the class WordLengthFinder to group

A passage of text is rated for difficulty by the length of the words it contains. You are to complete the class WordLengthFinder to group words by their length.

You are given a string. Create a Scanner to process the String. You are to print the words with the shortest words first. Within words of the same length, you are to print the words alphabetically.

You can use a Map where the keys are the Integer length and the values are the Set of the words of that length. This is similar to hw 17.

You can print the Set mySet like this: System.out.println(mySet);

For the string "Mary had a little lamb", the output would look like this

[a] [had] [Mary, lamb] [little] 

In order to get words without following punctuation, create a scanner for the String and set the delimiter to use: scan.useDelimiter("[^A-Za-z0-9]+");

Codecheck will run your program more than once. Note that the second string is fairly long and you will have to scroll right to see expected and actual output.

----------------------------------------------------

Complete the following file:

WordLengthFinder.java

import java.util.TreeSet; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; public class WordLengthFinder { public static void main(String[] args) { String passage = "mary had a little lamb"; }

}

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

Question

a. What is the purpose of the team?

Answered: 1 week ago