22.1 | ( Performing set operations on hash sets ) Create two hash sets { "George" , "Jim" , "John" , "Blake" , "Kevin" , "Michael" } and { "George" , "Katie" , "Kevin" , "Michelle" , "Ryan" }, and find their union, difference, and intersection. (You may clone the sets to preserve the original sets from being changed by these set methods .) |
22.2 | ( Displaying nonduplicate words in ascending order ) Write a program that reads words from a text file and displays all the nonduplicate words in ascending order. The text file is passed as a command-line argument. |
22.3** | ( Counting the keywords in Java source code ) Write a program that reads a Java source code file and reports the number of keywords in the file. Pass the Java file name from the command line. |
Hint
Create a set to store all the Java keywords. |
22.4 | ( Performing set operations on array lists ) Create two array lists { "George" , "Jim" , "John" , "Blake" , "Kevin" , "Michael" } and { "George" , "Katie" , "Kevin" , "Michelle" , "Ryan" }, and find their union, difference, and intersection. (You may clone the lists to preserve the original lists from being changed by these methods.) |
22.5* | ( Displaying words in ascending alphabetical order ) Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The text file is passed as a command-line argument. |
22.6* | ( Storing numbers in a linked list ) Write a program that lets the user enter numbers from a graphical user interface and display them in a text area, as shown in Figure 22.26. Use a linked list to store the numbers. Do not store duplicate numbers. Add the buttons Sort , Shuffle , and Reverse to sort, shuffle, and reverse the list. Figure 22.26. The program stores numbers in a list.
|
22.7* | ( Counting the occurrences of numbers entered ) Write a program that reads an unspecified number of integers and finds the one that has the most occurrences. Your input ends when the input is . For example, if you entered 2 3 40 3 5 4 “3 3 3 2 0 , the number 3 occurred most often. Please enter one number at a time. If not one but several numbers have the most occurrences, all of them should be reported . For example, since 9 and 3 appear twice in the list 9 30 3 9 3 2 4 , both should be reported. | ||
22.8** | ( Revising Listing 22.10, CountOccurrenceOfWords.java ) Rewrite Listing 22.10 to display the words in ascending order of occurrence counts. Hint
| ||
22.9** | ( Counting the occurrences of words in a text file ) Rewrite Listing 22.10 to read the text from a text file. The text file is passed as a command-line argument. | ||
22.10*** | ( Syntax highlighting ) Write a program that converts a Java file into an HTML file. In the HTML file, the keywords, comments, and literals are displayed in bold navy, green, and blue, respectively. Use the command line to pass a Java file and an HTML file. For example, the following command
converts Test.java into Test.HTML. Figure 22.27(a) shows a Java file. The corresponding HTML file is shown in Figure 22.27(b). Figure 22.27. The Java code in plain text in (a) is displayed in HTML with syntax-highlighted in (b). |