Data Structures and Algorithms in Java
Data Structures and Algorithms in Java
6th Edition
ISBN: 9781118771334
Author: Michael T. Goodrich
Publisher: WILEY
Question
Book Icon
Chapter 2, Problem 35P
Program Plan Intro

StringTest class

Program plan:

  • Import the required java packages.
  • Create a class StringTest that contains a list of words and then returns the count of each word in the list.
  • In main() function,
    • Create the list of words.
  • Create the method countWords()
    • Create the object for hash map.
    • If the input word is not equal to null then separate the list of words using white spaces.
    • Execute for loop until it ends with list of words. Inside the loop,
      • Check whether the particular string is present in the hash map.
      • If yes, then start count of each word and increment the word count by 1 if the word is repeated again in the string.
      • Otherwise, remain with the word count as “1”.
      • Finally, print the count of each word in a string.

Blurred answer
Students have asked these similar questions
Write a JAVA program that checks phrases to determine if they are palindromes.  A palindrome is a word, phrase, or sentence that reads left-to-right the same way it reads right-to-left, ignoring all punctuation and capitalization.  For example, the statement “Madam, I’m Adam” is a palindrome as the response of “Eve.”  Use a method to determine if a String is a palindrome.  Test a single word non-palindrome, a single word palindrome, a phrase that is not a palindrome, and a phrase that is a palindrome.  Print the phrase and whether it is a palindrome or not. Some simple palindromes are “racecar,” “taco cat,” and “A man, a plan, a canal, Panama!”  There are a few different approaches for the test; choose one of your liking. Hint: extract all letters, change the remaining letters to lowercase, then test if the phrase is a palindrome.
Write a Java program using at least one for loop that prints pictures of piles of counters of different sizes using ‘=‘ characters as shown below. Each counter should be an odd number of characters wide and be two characters longer than the counter above it. The user should, when asked, type in the size of the top and bottom counters. For example, if the user enters 3 for the top counter and 7 for the bottom counter then the image below should be printed. your program must make use of a counter-controlled for loop be in procedural programming style (not OOP)  your program should also be logically correct, solving the core problem, be elegantly written following good style, and be broken into appropriate methods that take arguments and/or return results.
Write a Java program that gets a list of numbers from the user and prints:
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education