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:
8
版本 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)));
….
}
}