Skip to content

TokenLengthsAnalyzer - Histogram

Objective

Create a dynamic histogram of the token lengths in the TokenLengthsAnalyzer.


Requirements

  1. In the TokenLengthsAnalyzer create a histogram of the output.

  2. Add the below entry to the analyzer.properties file.

  3. The value is the name of the output file for the histogram.
output.file.token.lengths.histogram=token_lengths_histogram.txt
  1. The histogram shows the distribution of token lengths in the file.

    • The histogram automatically adjusts (it's dynamic) for each file that is analyzed.
    • The value of each asterisk changes depending on the file being analyzed so that the histogram never exceeds 80 characters.
    • Always show at least one *.
    • The histogram output begins on the first line of the output file.

Commit History

Make sure to commit frequently to maintain a clear, well-documented history of your process and progress throughout the challenge.


Examples

Each row prints the token length followed by a string of asterisks representing how often this length appears in the file being analyzed.

1   ******************
2   *************************************************************
3   ****************************************************************************
4   **************************************************************
5   **********************************
6   *************************
7   *********************
8   **************
9   *********
10  *****
11  ***
12  **
13  *
14  *
15  *
16  *
17  *
18  *
19  *
29  *
31  *

Here’s an example of output for a smaller file.

This file only has 4 different lengths of tokens: 10 are 1 character in length, 20 are two characters in length, etc.

1   10
2   20
3   40
10  20

Here is the histogram output for the smaller file. The token length that occurs the most has a row of stars that stretches all the way to the right. The other rows are created accordingly. The rows for token lengths 2 and 10 are half as long as the row for token length of 3.

1   *******************
2   **************************************
3   ****************************************************************************
10  **************************************

Submission

  1. Take a screenshot, histogramTestsPass.png, showing the Challenge unit tests pass in the console.
  2. Take two screenshot(s) of the histogram output.

    1. Histogram screenshot 1: run the analyzer with a small file (~10 tokens in the file), name the screenshot histogramSmall.png
    2. Histogram screenshot 2: run the analyzer with a large file (bigFile.txt), name the screenshot histogramLarge.png
    3. Save it to the screenshots/challenges directory
  3. Push your code to GitHub

  4. Create an issue and name it "Challenge - Histogram".
  5. Reflect on this challenge: Copy the below text and paste it into the "Add a description" textarea.
@kkschumacher

1. What resources did you use to complete this challenge?

2. What does your commit history look like for this challenge? Does it clearly show your process and progress?

3. What obstacles did you overcome? 

4. What did you learn by completing this challenge?

Rubric

All of the following must be satisfied to achieve a "Met" status

  • Unit Tests: Must pass the Challenge unit tests.
  • Screenshots: Screenshots clearly shows expected output and tests passing.
  • Debugging & Problem-Solving: Code is free from errors.
  • Code Quality: Code is exceptionally clean, efficient, and maintainable. Follows best practices, coding standards, and programming principles.
  • Functionality: The histogram provides the correct output.
  • Code Documentation: Proper JavaDoc is used.
  • External Sources: External sources (websites, classmates, AI tools, etc), if utilized, are referenced and documented within the code as comments.