7. 字符数统计(满分50分)
版本1:满分15分
Write a method that counts the number of letters in a string using the following header:
public static int countLetters (String s)
Write a test program that prompts the user to enter a string and displays the number of
occurrences of letters in the string.
版本2:满分20分
Write a class that displays the number of occurrences of each letter in a string using
histogram. The class header should be:
public class Histogram extends JPanel { … }
Write a test program that prompts the user to enter a string and displays a histogram of the
number of occurrences of each letter in the string using Histogram class. The display is as shown
as following figure:
版本3:满分20分
Write a program that prompts the user to enter the name of an ASCII text file and display the
frequency of the letters in the file using following design:
public class ShowFrequency {
public static void main(String[] args) throws Exception {
….
BufferedInputStream fileInput = new BufferedInputStream(
new FileInputStream(new File(filename)));
….
}
}
1