CSE 8B Spring 2001
Homework #1

Required reading: Savitch text Chapter 6

Turn in due date: Wednesday April 11 (i.e., 8 am April 12)
Interview due date: Monday April 16.

Programming:
You may work in teams of two students, but once you form a team, you cannot change the team for this assignment. You may work alone if you prefer.

Write a program that will read in a line of text and output a list of all the letters that occur in the text along with the number of times each letter occurs. Your program will also output a list of characters other than letters that appear in the line. Each nonletter character should appear only once in the output. For the nonletters, you need not tell how many times each occurs. You will test for the end of the line by testing for '\n' or you may read the entire line using a method in SavitchIn. The letters should be listed in alphabetical order when they are output. Use an array of ints of length 26, each indexed variable contains the count of how many letters there are. Array indexed variable 0 contains the number of a's, array indexed variable 1 contains the number of b's, and so forth. Allow both upper- and lowercase letters as input, but treat uppercase and lowercase versions of the same letter as being equal. Store the nonletter characters in an array of char. You can assume that there are at most 20 nonletter characters in a line.

Hint: You will want to use one of the functions toUpperCase or toLowerCase in the wrapper class Character described in Chapter 5. You will find it helpful to define a method that takes a character as an argument and returns an int value that is the correct index for that character, such as 'a' returning 0, 'b' returning 1, and so forth.

Note that you can use a type cast to change a char to an int, like (int)letter. Of course, this will not get the number you want, but if you subtract (int)'a', you will then get the right index. Allow the user to repeat this task until the user says she or he is through.