Menu
Coddy logo textTech

Displaying the Analysis

Part of the Logic & Flow section of Coddy's Dart journey — lesson 57 of 65.

challenge icon

Challenge

Easy

In 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.

  1. Use all the variables from your previous project steps:
    • textToAnalyze from your project setup
    • totalCharacters from your character counting step
    • wordList from your word splitting step
    • totalWords from your word counting step
    • uniqueWordsSet from your unique word counting step
    • uniqueWordCount from your unique word counting step
    • wordFrequency from your word frequency counter step
  2. Create a comprehensive final report that displays all analysis results
  3. Format the output to show a complete summary of the text analysis
  4. Include all statistics with clear labels and proper formatting
  5. 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