Displaying the Analysis
Part of the Logic & Flow section of Coddy's Dart journey — lesson 57 of 65.
Challenge
EasyIn this final lesson of the Text Analyzer project, you'll create a comprehensive display of all the analysis results you've collected throughout the project. This step will format and present all the statistics in a clear, professional summary that showcases the complete text analysis.
- Use all the variables from your previous project steps:
textToAnalyzefrom your project setuptotalCharactersfrom your character counting stepwordListfrom your word splitting steptotalWordsfrom your word counting stepuniqueWordsSetfrom your unique word counting stepuniqueWordCountfrom your unique word counting stepwordFrequencyfrom your word frequency counter step
- Create a comprehensive final report that displays all analysis results
- Format the output to show a complete summary of the text analysis
- Include all statistics with clear labels and proper formatting
- Display the results in the exact format shown below
For example, if your text analyzer was set up with "hello world hello", your program should output:
=======================================
TEXT ANALYSIS COMPLETE REPORT
=======================================
Original Text: "hello world hello"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 17
- Total Words: 3
- Unique Words: 2
- Most Common Word: hello (appears 2 times)
=======================================
DETAILED BREAKDOWN:
Word List: [hello, world, hello]
Unique Words Set: {hello, world}
Word Frequency Map: {hello: 2, world: 1}
=======================================
Analysis completed successfully!
Text contains 2 unique words out of 3 total words.
=======================================If your text analyzer was set up with "the cat and the dog and the bird", your program should output:
=======================================
TEXT ANALYSIS COMPLETE REPORT
=======================================
Original Text: "the cat and the dog and the bird"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 33
- Total Words: 8
- Unique Words: 5
- Most Common Word: the (appears 3 times)
=======================================
DETAILED BREAKDOWN:
Word List: [the, cat, and, the, dog, and, the, bird]
Unique Words Set: {the, cat, and, dog, bird}
Word Frequency Map: {the: 3, cat: 1, and: 2, dog: 1, bird: 1}
=======================================
Analysis completed successfully!
Text contains 5 unique words out of 8 total words.
=======================================If your text analyzer was set up with "apple banana apple cherry banana apple", your program should output:
=======================================
TEXT ANALYSIS COMPLETE REPORT
=======================================
Original Text: "apple banana apple cherry banana apple"
=======================================
ANALYSIS SUMMARY:
- Total Characters: 38
- Total Words: 6
- Unique Words: 3
- Most Common Word: apple (appears 3 times)
=======================================
DETAILED BREAKDOWN:
Word List: [apple, banana, apple, cherry, banana, apple]
Unique Words Set: {apple, banana, cherry}
Word Frequency Map: {apple: 3, banana: 2, cherry: 1}
=======================================
Analysis completed successfully!
Text contains 3 unique words out of 6 total words.
=======================================Your program should determine the most common word by finding the word with the highest frequency count in the wordFrequency map. Use string interpolation to display all the collected data in a professional, easy-to-read format. This final display brings together all the analysis work you've completed throughout the project into one comprehensive summary.
Try it yourself
import 'dart:io';
void main() {
String? textToAnalyze = stdin.readLineSync();
int totalCharacters = textToAnalyze!.length;
List<String> wordList = textToAnalyze.split(' ');
int totalWords = wordList.length;
Set<String> uniqueWordsSet = wordList.toSet();
int uniqueWordCount = uniqueWordsSet.length;
Map<String, int> wordFrequency = {};
for (String word in wordList) {
if (wordFrequency.containsKey(word)) {
wordFrequency[word] = wordFrequency[word]! + 1;
} else {
wordFrequency[word] = 1;
}
}
print('Text Analysis Tool - Word Frequency');
print('====================================');
print('Analyzing text: "$textToAnalyze"');
print('Total characters: $totalCharacters');
print('Words found: $wordList');
print('Total words: $totalWords');
print('Unique words: $uniqueWordsSet');
print('Unique word count: $uniqueWordCount');
print('====================================');
print('Word Frequency Analysis Results:');
print('Word frequencies: $wordFrequency');
print('====================================');
print('Word frequency analysis completed successfully.');
}All lessons in Logic & Flow
1Advanced List Manipulation
List Properties: first & lastList State: isEmpty & isNotEmpReversing a ListAdding to a List: insertList Removal: removeWhereFinding in a List: indexOfSorting a ListShuffling a ListRecap - List Organizer4Advanced Map Manipulation
Iterating Over a MapChecking for Keys and ValuesMap Properties: keys & valuesConditional Add: putIfAbsentRemoving Entries from a MapNested MapsRecap - Inventory Update2Functional List Operations
Transforming with 'map'Filtering with 'where'Using '.toList()'Checking Conditions with 'any'Conditions with 'every'Finding with 'firstWhere'Recap - Data Filtering5Project: Shopping Cart Calc
Project SetupAdding Items to the Cart8Project: Simple Text Analyzer
Project Overview and SetupCounting Characters3Sets
What is a Set?Creating a SetAdding and Removing from SetsChecking for Elements in a SetConverting a List to a SetSet UnionSet IntersectionSet DifferenceRecap - Unique Guest List