Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[ ] the I ask ior Inis Lab Work Attempts Write a program that Unlimited counts the occurrences of each reserved word in a Java
the I ask ior Inis Lab Work
Attempts
Write a program that
Unlimited
counts the occurrences of each reserved word in a Java code file whose name is read from the user console by using a hash set javautil.HashSet
stores each reserved word that is found in the file with its count by using a tree map javautil. TreeMap
and prints the reserved words in alphabetical order with the number of the occurrences for each word.
Note: Your program must ignore each reserved word that is contained in a comment or in a string.
Assume that the Java source code file given to your program is correct and assume also that the line comments starting with and the multiline comments between and do not overlap.
The given file for testing your program TestFilejava and the expected console output for that file are shown on the next slide.
See the given two example codes.
CountReservedWords.java A program that counts the reserved words in a Java source code file by using Java's own hash set implementation javautil.HashSet and prints the total count.
CountOccurrencesOfWords.java A program that counts the occurrences of words in a string and prints the words in alphabetical order with the number of the occurrences for each word by using Java's own tree map implementation javautil.TreeMap
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started