Repetition and Files again: Counting Letters: Fall 2025

02 Aug 2025 - 21:59 | Version 1 |

Learning Objective(s)

  • Nested loops
  • Count controlled loops
  • Catching exceptions
  • More experience with sequential files

Overview of the Program

Write a program that displays the number of each letter on each line. It needs to do all of one letter before moving on to the next letter.

Specifics

  • The program is to be called CountLetters.
  • The program should prompt for the name of the file to be processed.
  • Exceptions must be caught and properly handled.
  • If a letter does not occur on a line (or in the file), it should not be displayed.
  • You may assume the file only contains lowercase letters.

Sample dialogue

Below is a sample dialogue. The prompts may vary but the input given by the user is to be the same format. Your output can vary somewhat as long as the required data is nicely displayed in the order specified.
What file would you liked to have processed? small.txt
Line 1 has 1 a's.
Line 2 has 1 a's.
Line 4 has 1 a's.
Line 4 has 1 d's.
Line 2 has 1 e's.
Line 4 has 1 e's.
Line 2 has 1 f's.
Line 4 has 1 f's.
Line 1 has 1 h's.
Line 3 has 1 h's.
Line 1 has 2 i's.
Line 2 has 1 i's.
Line 3 has 1 i's.
Line 3 has 1 j's.
Line 2 has 3 l's.
Line 2 has 1 m's.
Line 4 has 1 o's.
Line 4 has 1 r's.
Line 1 has 2 s's.
Line 2 has 1 s's.
Line 3 has 1 s's.
Line 4 has 1 s's.
Line 1 has 1 t's.
Line 3 has 2 t's.
Line 3 has 1 u's.
Line 3 has 1 w's.
Line 4 has 2 w's.
You can also run a solution for this program if you want. See classroom instructions for more details.

Lab Hints

Submission

  • Create a software development report
    • For the system design, you need to make your own flowchart.
    • For testing report,
      • make sure your tests ensure that each statement is executed at least one.
      • your expected output CANNOT be pasted from the dialogue of a running. Only the actual output may be pasted
      • It should contain at least one different input that is an "error"
    • For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem
    • create a pdf document from your software development report
    • create an empty zip folder
    • place only CountLetters.java, your own testing files (not mine) and your pdf document into it
    • submit the zip folder on canvas

Optional improvements

Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
  1. Treat uppercase letters as lowercase letters
  2. For each letter in the file, print the first line and last line that contain that letter (after printing how many letters in each line).
  3. Submission instructions
    1. Call this program CountLetters2 add it to the zip folder that contains the original solution.
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback
This website is using cookies. More info. That's Fine