Question
Exercise 3A [5%] Create a class called TextStatisticsDisplay. Extend this class from JComponent. Add a private variable of type TextStatistics. If you have not completed
Exercise 3A [5%] Create a class called TextStatisticsDisplay. Extend this class from JComponent. Add a private variable of type TextStatistics. If you have not completed Exercise 1 replace TextStatistics with an int array with 36 elements in all Exercises. Exercise 3B [5%] Add a constructor to the class that receives a TextStatistics parameter. Initialise the variable you created in 3A with this parameter. If you have not completed Exercise 1 initialise the int array with an int array parameter. 2 Exercise 3C [25%] Override the paintComponent method. Draw a rectangle for each letter and number. The height of the rectangle should correspond to the frequency of this symbol. If an element has a frequency has 80 elements it does not have to be 80 pixels but can be a multiple e.g. 800 pixels. Each rectangle should be placed next to its neighbour. On top of each rectangle place the symbol whose frequency the rectangle represents followed by a colon, a space and the frequency. E.g. if the e occurred 83 times in the text you should write e: 83 over the corresponding bar. See Figure 1 for an example. If you did not complete Exercise 1 use the values from the int array. Figure 1: An example JFrame (1500x1000) displaying the frequencies found in the text. Exercise 3D [5%] Create another class called MyMain with a main method. In this main method use TextIO to read the text in input.txt (available on Moodle) into a TextStatistics object. If you did not complete the Exercise 1 and 2 create an int array with 36 elements and assign each element a random number between 0 and 99. Create a JFrame with size 1500 x 1000 pixels and add a TextStatisticsDisplay object to it. Provide the TextStatistics object or the int array you just read to the TextStatisticsDisplay constructor. Make the JFrame visible. You will have to surround the code with an appropriate try/catch block.
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