Delivery in day(s): 4
Histogram JAVA Programming Assignment Brief
A histogram is a statistic measure that calculates the occurrence of a variable. Write two programs that read a file and display a histogram to show the occurrences of each letter in the file. The first JAVA program is text based, and the second JAVA program is GUIbased.
Program 1 (TextBased)
The program accepts one command line argument, which is the filename of the text to be read? for example:
java histogram <filename>
where <filename> is the name of the input text file. The program then reads this file and calculates the histogram of each letter and displays the histogram in the following order:
- the total number of characters counted (only include AZ)?
- the letters in upper case?
- the occurrence of the letters and the percentage? and
- a series of asterisks showing the percentage of each occurrence. The program outputs a vertical bar for every 10 asterisks.
The letter with the largest occurrence should have 50 asterisks and the number of asterisks for the rest of the letters should be proportionally scaled to the letter with the highest count. The next section explains how to calculate the number of asterisks to be displayed.
The letter E has the highest occurrence with a count of 1,000 and it makes up 18.04% of the characters, so it has 50 asterisks. The letter ‘A’ makes up 5.41% of the characters, and has 15 asterisks because 5.41/18.04*50 = 15. The program should round the number of asterisks down to the nearest integer value.
The program should also conserve the output space by carefully formatting the count for each letter and the percentage of each letter so these outputs only use a minimum amount of space but still appear in neat columns. For example, if the largest number of characters is in the hundreds,
Program 2 (GUIBased)
Write a program that displays the histogram using a GUI. The file name is entered from a text field. Pressing the Enter key on the text field or clicking on the view button causes the program to start to read and process the file and display the histogram. The histogram is displayed in the center of the window (see Figure 1). Note that you do not have to display the count or the percentage.
This assignment requires you to
- develop a textbased and a GUIbased Java programming.
- to write test cases using JUnit.
This assignment aligns with the following learning outcomes:
- be able to design and construct Java Graphical User Interfaces (GUI) that interact with problem domain objects?
- be able to construct and demonstrate the use of reusable software elements utilising JavaBeans?
- be able to demonstrate the use of the inheritance features of the Java language to design and implement complex objectoriented programs.