Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called \'Histogram\'. The Histogram class will keep track of the

ID: 3624101 • Letter: C

Question

Create a class called 'Histogram'. The Histogram class will keep track of the frequency of integers (only) between 0 and an upper bound (inclusive) specified upon creation of a new Histogram object. (More than one independent histogram instance can exist at the same time, so the class is instantiable.) Use an array of integers to hold the number of times each integer in the range appears, and provide reasonable error checking/ correction within the constructor as needed. An integer's frequency will be updated each time a new integer data item is "added" to the Histogram object.

A modifier add(int) will be used to enter a new data item into the histogram. add(int) will need to check to see if the data item is within range of the histogram and silently discard it if it is not within the histogram's range. Include a display() method to print the contents of the histogram to the screen.

For example, upon creating a new Histogram: Histogram(5), an instance array will be created that is indexed from 0 to 5. Initially, it should be set to all zeroes and will appear as follows:

h[0] = 0

h[1] = 0

h[2] = 0

h[3] = 0

h[4] = 0

h[5] = 0



Upon successive updates with add(int), as shown below,

add(0);

add(0);

add(5);

add(7); // out of range, to be discarded

add(5);

add(2);

add(-2); // out of range, to be discarded

add(5);



the resulting array will look like this:

h[0] = 2

h[1] = 0

h[2] = 1

h[3] = 0

h[4] = 0

h[5] = 3



2 points: Other than constructors and the add() method, what accessor methods should you include with your Histogram class? Why? Should there be a method to display the Histogram? Why or why not? (There is not a single correct answer for this.) Explain your reasoning in your readme file; your grade will depend on the quality of your argument.

8 points: Write a main driver method to thoroughly test your Histogram class. This may be included for convenience within the Histogram class, or you may write a separate application class. Include this main method in your submission for your homework. Also copy the output into your readme file and explain briefly why it shows that your Histogram is correct.

Explanation / Answer

Here you go: public class Histogram { private int[] values; public Histogram(int upperbound) { values = new int[upperbound +1]; } public void add(int value) { if (value
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote