Question: How to write a FrequencyHistogram program that meets the following requirements in Java? 1. It's constructor should take a parameter holding some text in a
How to write a FrequencyHistogram program that meets the following requirements in Java?
1. It's constructor should take a parameter holding some text in a String variable. The constructor will calculate the frequency histogram for the text by calling a private method buildHistogram() .
2. The histogram should be stored as an array of integer counts, which is how many times a character appears in the document. The entry at index 0 should hold the number of times 'A' appears, index 1 the number of times 'B' appears, and so on.
3. The class should provide highestFrequencyIndex() and highestFrequencyChar() methods that return the index in the array and the corresponding character, respectively, at which the highest frequency in the histogram occurs.
4. The class should implement a determineShift() method which takes another object otherHistogram of type FrequencyHistogramand return the integer shift between them. The integer shift is defined as this.highestFrequencyIndex() - otherHistogram.highestFrequencyIndex() .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
