Question
Write a Java program called Histogram.java that displays a list of distinct characters in an input file and the occurrence of each character. Your program
Write a Java program called Histogram.java that displays a list of distinct characters in an input file and the occurrence of each character. Your program should read an input file name from a user. After that, your program should read characters in the file and display a list of distinct characters and their occurrences. Finally, your program should draw a vertical bar for the occurrences.
In the assignment, you can assume that the number of characters in the input file is less than 200. You can also assume that each line has only one character and theres no extra blank space after each character. Furthermore, you can assume that all characters are capitals and from A to K.
For the assignment, your program has to display the result exactly as the sample run. For instance, when you display a list of character occurrences, your program should display the characters with more than zero occurrence in the ascending order. The height of the vertical bar should be the same as the maximum value of Occurrence. And also, the characters in the vertical bar should come in the order of occurrences. In other words, since the characters from D to K have occurrence 0, it comes first. After that, characters A and C come next because their occurrences are 1. Finally, B is displayed because its occurrence is 3.
A sample run of your program MUST be like below:
Input filename: C:\\tmpt1.txt Input filename: c:\\tmp\\t2.txt Char Occurrence Char Occurrence Vertical Bar Vertical Bar 13 13 I INo D E F G H I J K A C B INO I C E F G I JAKBDH For the sample run, tl.txt has the following context For the sample run, t2.txt has the following context
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started