Question: When I tried to compile this example I got 5 error messages. The example instructions for this program is below, and the error messages are
When I tried to compile this example I got 5 error messages.
The example instructions for this program is below, and the error messages are further below.
Ex) Create a PhraseAnalyzer program using isValidPhrase(), getWords(), getSmallestWords(), getLargestWords(), getAverageWordLength(), and getLetterTally() methods. The program should prompt the user to insert a phrase and the program should produce a list including the smallest word used, largest word used, average word length, least frequently used letters, and most frequently used letter. The phrase must also be valid, meaning characters that are not letters or not valid but letters that do not form a word can still count as a word. Ex: asdhj is considered valid.
PhraseAnalyzer.java:90: error: ';' expected in the event that (analyzer.isValidPhrase()) { ^ PhraseAnalyzer.java:90: error: ';' expected in the event that (analyzer.isValidPhrase()) { ^ PhraseAnalyzer.java:90: error: ';' expected in the event that (analyzer.isValidPhrase()) { ^ PhraseAnalyzer.java:101: error: 'else' without 'if' } else { ^ PhraseAnalyzer.java:105: error:
Here is the code below
import java.util.*;
/** * The PhraseAnalyzer class breaks down phrases and gives data about them. */ public class PhraseAnalyzer {
private String phrase;
/** * Builds a PhraseAnalyzer object with the given expression. * * @param phrase the expression to be broke down */ public PhraseAnalyzer(String phrase) { this.phrase = phrase; }
/** * Checks whether the expression is legitimate. * * @return true if the expression is valid, false otherwise */ public boolean isValidPhrase() { return phrase != null && !phrase.isEmpty(); }
/** * Returns an array of words in the expression. * * @return an array of words in the expression */ public String[] getWords() { return phrase.split("\\s+"); }
/** * Returns the smallest words in the expression. * * @return the smallest words in the expression */ public String[] getSmallestWords() { List
/** * Returns the largest words in the expression. * * @return the largest words in the expression */ public String[] getLargestWords() { List
/** * Returns the average word length in the expression. * * @return the average word length in the expression */ public double getAverageWordLength() { String[] words = getWords(); int totalLength = Arrays.stream(words).mapToInt(String::length).sum(); return (double) totalLength / words.length; }
/** * Returns a map of letter counts in the expression. * * @return a map of letter counts in the expression */ public Map
Can someone fix my current example program and then establish what this means? I'm new to coding so help is very much appreciated.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
