```plaintext /* Sample Output: Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. This is my phrase The longest word in your phrase is "phrase" with 6 characters. Your phrase has 4 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Hi Your phrase must contain at least 5 characters. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Bye Your phrase must contain at least 5 characters. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Hello The longest word in your phrase is "Hello" with 5 characters. Your phrase has 1 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Now I will try with a very long phrase that contains many words The longest word in your phrase is "contains" with 8 characters. Your phrase has 13 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Programming is cool The longest word in your phrase is "Programming" with 11 characters. Your phrase has 3 words in it. */ ``` ```java import java.util.Scanner; public class Main { public static void main(String[] args) { String phrase; int numWords; phrase = inputPhrase(); numWords = analyzePhrase(phrase); System.out.println("Your phrase has " + numWords + " words in it."); System.out.println(); } /** * inputPhrase method * Ask the user to input a phrase, and make sure it is at least 5 characters long. * (Use a loop to make the user input a new phrase if it is too short.) * @return the phrase */ // INSERT YOUR CODE HERE /** * analyzePhrase method * Count the number of words in a given string, and determine its longest word. * Assume the string is well formed and doesn't have leading * or trailing spaces, or multiple spaces in a row. * Return the number of words. * Output the longest word on the screen (console). * @param str string to analyze * @return number of words in str */ // INSERT YOUR CODE HERE /* Hints: * To count words and determine their lengths, I recommend you use a for-loop to go * through each character one at a time, using .charAt and then when you see a * space ' ' count the word and set a variable to remember which character number * that was, so you can calculate how long each word is. Use a variable for the * longest word seen so far, and compare each word as you see it, to determine if * it is longer than the longest word seen so far. If so, update that to the * longest word seen so far. Don’t forget about the final word, which doesn’t end * with a space. */ } ``` Description: This Java code contains a `Main` class with a `main` method designed to analyze a user-input phrase. The program will count the number of words in the phrase and identify the longest word. The code currently includes two stub methods: `inputPhrase` and `analyzePhrase`, where the logic for input validation and analysis is intended to be implemented. The `inputPhrase` method should ensure the user inputs a string of at least 5 characters, while the `analyzePhrase` method
```plaintext /* Sample Output: Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. This is my phrase The longest word in your phrase is "phrase" with 6 characters. Your phrase has 4 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Hi Your phrase must contain at least 5 characters. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Bye Your phrase must contain at least 5 characters. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Hello The longest word in your phrase is "Hello" with 5 characters. Your phrase has 1 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Now I will try with a very long phrase that contains many words The longest word in your phrase is "contains" with 8 characters. Your phrase has 13 words in it. Please enter a phrase all on one line, with just one space separating each word, and no spaces at the beginning or end of the phrase. Programming is cool The longest word in your phrase is "Programming" with 11 characters. Your phrase has 3 words in it. */ ``` ```java import java.util.Scanner; public class Main { public static void main(String[] args) { String phrase; int numWords; phrase = inputPhrase(); numWords = analyzePhrase(phrase); System.out.println("Your phrase has " + numWords + " words in it."); System.out.println(); } /** * inputPhrase method * Ask the user to input a phrase, and make sure it is at least 5 characters long. * (Use a loop to make the user input a new phrase if it is too short.) * @return the phrase */ // INSERT YOUR CODE HERE /** * analyzePhrase method * Count the number of words in a given string, and determine its longest word. * Assume the string is well formed and doesn't have leading * or trailing spaces, or multiple spaces in a row. * Return the number of words. * Output the longest word on the screen (console). * @param str string to analyze * @return number of words in str */ // INSERT YOUR CODE HERE /* Hints: * To count words and determine their lengths, I recommend you use a for-loop to go * through each character one at a time, using .charAt and then when you see a * space ' ' count the word and set a variable to remember which character number * that was, so you can calculate how long each word is. Use a variable for the * longest word seen so far, and compare each word as you see it, to determine if * it is longer than the longest word seen so far. If so, update that to the * longest word seen so far. Don’t forget about the final word, which doesn’t end * with a space. */ } ``` Description: This Java code contains a `Main` class with a `main` method designed to analyze a user-input phrase. The program will count the number of words in the phrase and identify the longest word. The code currently includes two stub methods: `inputPhrase` and `analyzePhrase`, where the logic for input validation and analysis is intended to be implemented. The `inputPhrase` method should ensure the user inputs a string of at least 5 characters, while the `analyzePhrase` method
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Complete the Java program
Sample Output in the picture
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education