Letter Count Program in Java: Read, Analyze and Output Letter Frequencies, Exams of Computer Science

A java programming assignment where students are required to write a program that reads a series of input lines as text, counts the number of occurrences of each letter in the input, and produces output with the echoed input, the number of occurrences of each letter, the most frequent letter, and the least frequent letter. Students are provided with guidelines on how to structure their program, including methods for updating the count array, determining the most and least frequent letters, and printing the final results.

Typology: Exams

Pre 2010

Uploaded on 07/30/2009

koofers-user-vye
koofers-user-vye 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Science 2311
Labs 13 and 14
Write a program complete with full documentation to: (1) read a series of input lines as text;
(2) count the number of occurrences of each letter in the input; and (3) produce as output the
following information.
the echoed input
the number of occurrences of each letter in the input, one letter per line
the letter which occurred the most
the letter which occurred the least
See the last page for a sample input file and the corresponding output.
PROGRAM DETAILS
Initial source file: You may download a template for the source file from the 2310 home
page. The name of your source file should be LetCount.java
Indexing an array with a character: As we have studied in class, array indices always start
with 0 in Java. However, in this program, it is logically useful to think of arrays as being
indexed by letters. For example, count[‘C’] could logically represent the number of times
C appears in the input. However, in order to map ‘C’ to a valid Java array index, I have
defined in the source file template a method addr that takes as input the character code, and
produces as output the correct array index. This mapping will produce 1 for the letter ‘A’,
2 for the letter ‘B’, etc. Thus within the program, count[addr(‘C’)] will represent the
number of times the letter C appears in the output. For the sample input on the last page,
count[addr('P')] should equal 10 at the end of the execution.
Determining if a character is a letter: We will assume that there are no lower case letters.
Use the appropriate static method or methods from the Character class (see page 376).
I/O information. I would suggest that you put your input data in a file and use I/O
redirection. You should be able to use the hasNext() method to determine when you’ve
reached the end of input and use nextLine() to store an input line into a String object from
where you can check each character and update your count array as appropriate.
Required methods (Documentation should be completed as each function is written).
Besides your main method which should declare needed variables and provide the control
loop for reading and processing the input you must define the following methods as a
minimum that your main method will use. All should be defined as public static in your
LetCount.java file.
1. A method that takes as parameters the count array and your String object containing the
most recently read line and goes character by character updating the count of each letter.
2. A method that takes the final counts and returns the letter that occurs the most
frequently.
pf3

Partial preview of the text

Download Letter Count Program in Java: Read, Analyze and Output Letter Frequencies and more Exams Computer Science in PDF only on Docsity!

Computer Science 2311

Labs 13 and 14

Write a program complete with full documentation to: (1) read a series of input lines as text; (2) count the number of occurrences of each letter in the input; and (3) produce as output the following information.

  • the echoed input
  • the number of occurrences of each letter in the input, one letter per line
  • the letter which occurred the most
  • the letter which occurred the least

See the last page for a sample input file and the corresponding output.

PROGRAM DETAILS

  • Initial source file: You may download a template for the source file from the 2310 home page. The name of your source file should be LetCount.java
  • Indexing an array with a character: As we have studied in class, array indices always start with 0 in Java. However, in this program, it is logically useful to think of arrays as being indexed by letters. For example, count[‘C’] could logically represent the number of times C appears in the input. However, in order to map ‘C’ to a valid Java array index, I have defined in the source file template a method addr that takes as input the character code, and produces as output the correct array index. This mapping will produce 1 for the letter ‘A’, 2 for the letter ‘B’, etc. Thus within the program, count[addr(‘C’)] will represent the number of times the letter C appears in the output. For the sample input on the last page, count[addr('P')] should equal 10 at the end of the execution.
  • Determining if a character is a letter: We will assume that there are no lower case letters. Use the appropriate static method or methods from the Character class (see page 376).
  • I/O information. I would suggest that you put your input data in a file and use I/O redirection. You should be able to use the hasNext() method to determine when you’ve reached the end of input and use nextLine() to store an input line into a String object from where you can check each character and update your count array as appropriate.
  • Required methods (Documentation should be completed as each function is written). Besides your main method which should declare needed variables and provide the control loop for reading and processing the input you must define the following methods as a minimum that your main method will use. All should be defined as public static in your LetCount.java file.
    1. A method that takes as parameters the count array and your String object containing the most recently read line and goes character by character updating the count of each letter.
    2. A method that takes the final counts and returns the letter that occurs the most frequently.
  1. A method like #2 except it returns the letter that occurs the least frequently.
  2. A method for printing the final results (i.e. the information that appears in the output after the echoing of the last input line.
  • Step 1 in your program development should be to write code in the main program that can simply read each line of input into a string and echo it back to standard output. Be sure you test this to see if it works before proceeding.
  • Step 2 should be to add method #1 mentioned above and the portion of method #4 that outputs the line by line results of the count for each letter.
  • Step 3 should be to add the methods for determining the most and least frequently occurring letters and add that to the output. As you are proceeding with the development, your “final results print” method is likely to evolve in terms of the number of parameters it needs.
  • Submission information: Name your file LetCount.java and place in a separate subdirectory with a name of your choice. Use the command submit l13 LetCount.java to electronically submit your assignment.
  • Your program will be evaluated on the basis of its correctness, the neatness and informativeness of its output and prompts, and your adherence to the programming standards of this class.
  • This problem is worth 100 points subdivided as follows: correctness - 90 points and adherence to standards 10 points. Correctness is subdivided as follows: proper counting and output - 70 points; finding min and max - 20 points. A program that does not compile will receive zero points.

DUE DATE: Tuesday April 28 at 11:00 A.M (no late submissions accepted)