Question: Histogram.java Description Write a Java program called Histogram.java that displays a count of distinct characters from an input file and the occurrences of each character.

Histogram.java

Description

Write a Java program called Histogram.java that displays a count of distinct characters from an input file and the occurrences of each character. Your program will read an input filename from a user. The program will then read characters from the file and display a list of distinct characters and their occurrences. Finally, the program will draw a vertical bar made up of the letters for the occurrences.

The end result should be exactly like the sample runs. For instance, when displaying a list of character occurrences, your program should display the characters with more than zero occurrence in descending order. The height of the vertical bar should be the same as the maximum value of Occurrence.

Assumptions

Assume that the number of characters in the input file is less than or equal to 200. You may also assume that each line has only one character and theres no extra blank space after each character. Furthermore, you can assume that the only characters will be capitals from A to K.

Description 1

Assumptions 1

Requirements 2

Include an abstract at the beginning of your file with the following information 2

Sample run 1 3

Sample run 2 4

Required methods

This program requires the following methods

  • public static void main(String[] args)

    • This will be the driver for our program. It will call the following methods.

  • public static String getFileName()

    • This method will read the filename from the user

  • public static void read(char[] letter, int[] letterCount, String filename)

    • This method will read the letters from the filename provided in the previous method

  • public static void sort(char[] letter, int[] letterCount)

    • This method will sort the letters

  • public static void display(char[] letter, int[] count)

    • This method will display the histogram

Requirements

Include an abstract at the beginning of your file with the following information

  1. Title: File Name

  2. Abstract: Overall purpose (or functionality) of the program.

  3. Author: Your name

  4. Date: The date you wrote the program

Your program will be graded based on

  1. Filename MUST be Histogram.java

  2. Compilation without error.

  3. Correct output result.

  4. Low MOSS score compared to other students

    1. I check against all submissions as well as submissions from previous semesters.

    2. Please reference the CSUMB academic integrity policies.

  5. Good programming structure

  6. Correct methods and method names.

  7. Comments. (Title, Abstract, Author, and Date are mandatory.)

  8. Meaningful and related variable names.

Sample run 1

For the sample run1 , tq2.txt contains:

B

A

C

B

B

C

Sample run 2

For sample run 2, tq3.txt has the following context:

H

A

D

B

B

K

H

D

H

H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!