Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 [Total 20%] Exercise 1A [5%] Create a class called TextStatistics. Add two private variables to the class. An int array with 26 elements

image text in transcribed
image text in transcribed
image text in transcribed
Exercise 1 [Total 20\%] Exercise 1A [5\%] Create a class called TextStatistics. Add two private variables to the class. An int array with 26 elements to store the frequencies of letters in a text and an int array with 10 elements to store the frequencies of numbers in a text. Both variables should be declared and initialised to arrays with default values. The class should not have a non-default constructor. In this exercise we will not consider any other symbols besides letters and numbers. Exercise 1B [5\%] Add four public methods: - A method that returns void called incrementLetterFrequency that has an int as parameter. This method should increment the frequency of the letter whose index in the array is given by the parameter. - A method that returns void called incrementNumberFrequency that has an int as parameter. This method should increment the frequency of the letter whose index in the array is given by the parameter. - A method that returns int called getLet terFrequency that has an int as parameter. This method should return the frequency of the letter whose index in the array is given by the parameter. - A method that returns int called getNumberfrequency that has an int as parameter. This method should return the frequency of the letter whose index in the array is given by the parameter. Exercise 1C [10\%] Override the tostring() method. The returned String should have this format with the values following the : corresponding to the frequencies of the corresponding alphanumeric symbols (letter and number frequencies should be printed in two separate lines (there are more lines in the example due to the limited page width)): a: 43,b:5,c:25,d:2, e: 83,f:10,g:8,h:16, i: 39,j:1,k:10,1:19, m:17,n:29,0:51,p:15,q:1,r:50,5:46,t:43,u:23,v:2, w: 9,x:6, y:11,z:1 :1,1:4,2:6,3:,4:1,5:2,6:1,7:,8:,9: Exercise 2 [Total 30\%] Exercise 2A [5\%] Create a class called TextIo. Exercise 2B [25\%] Add a public and static method called readText that returns TextStatistics. The method should have a String parameter that specifies a file name (and optionally path). Read the specified file and count the frequency of each Latin letter and Arabic number and update the frequencies in the TextStatistics object that the method returns. Your method should declare an appropriate exception. Should you have not completed Exercise 1, add a private an int array with 36 elements to store the frequencies of alphanumeric symbols in the text. Store the Latin letters in the text in the first 26 elements and the Arabic numbers in the last 10 elements. Retum the array instead of the TextStatistics object. You can test this class using input . txt (available on Moodle). Exercise 3 [Total 40% ] 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. Exercise 3C [25\%] Override the paint Component 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 (15001000) 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 15001000 pixels and add a TextstatisticsDisplay object to it. Provide the TextStatisties 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

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions