CIS 180: Object-Oriented Programming
Homework #10

Character Counts

Due December 12, 2011


The objectives of this homework are:

Problem Statement

For this project you are asked to design and implement a simple application that allows the user to enter some text (by typing or pasting), and counts the number of occurrences of each letter in the input. The application should contain two text areas, one for the user input and one for the program's output. There should also be a button for the user to click when they want to see the character counts. After entering text in the input area and clicking the button, the application should look like the following sample:

The program should count both uppercase and lowercase letters, but the output should not distinguish between the two. Characters other than letters (digits, punctuation, etc.) should not be counted. The user can edit the text in the input area, and get updated character counts at any time by clicking the button.

The sample solution uses a JSplitPane. You are not requried to use the split pane, but you can read the documentation for it if you want to use it.


Draw a UML class diagram to design your application, showing all of the fields and methods, including their accessibility (public or private) and data types.


The obvious approach is to scan the user input 26 times, first counting the A's, then the B's, and so on. However, this is very inefficient. Your program should only scan the input once. Furthermore, you should not write any nested if-else or switch statements to compare characters to each letter of the alphabet:

    if (c == 'A' or c == 'a') {
    else if (c == 'B' or c == 'b') {

    switch(c) {
       case A:
       case a:
      case B:
      case b:


The trick is to store the character counts in an array of ints, and if one of the input characters is an uppercase or lowercase letter, calculate the index of the array to update based on the character's value.


What to turn in

When your assignment is complete, add some comments to the comment block of the java source code explaining any problems you encountered in completing the assignment and describing any bugs in your solution.

Submit your source code as well as your class diagram as email attachments to your lab instructor. Alternatively, you may submit your class diagram in hardcopy. Use the subject line CIS-180 HW#10 in your email.

Make sure you send your homework to the proper place. Homework sent to the wrong address may not receive credit!

Lab SectionGraderEmail
L1 Mon. 2PM Wes Fowlks
L2 Wed. 9AM Neelima Mothe
L3 Wed. 1PM Wes Fowlks

There will be a 10% penalty for assignments received after the due date. Assignments will not be accepted more than one week past the due date.