Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3. (project) The program given below count keywords in a Java source file. Revise the program such that keywords in comments are disregarded. import java.util.*;

image text in transcribed
image text in transcribed
image text in transcribed
3. (project) The program given below count keywords in a Java source file. Revise the program such that keywords in comments are disregarded. import java.util.*; import java.io.*; public class CountKeywords { public static void main(String[] args) throws Exception { Scanner input = new Scanner(System.in); System.out.print("Enter a Java source file: "); String filename - input.nextLine(); File file = new File(filename); if (file, exists()) { System.out.println("The number of keywords in " + filename + " is " + countKeywords (file)); } else { System.out.println("File" + filename + does not exist."); } public static int countKeywords (File file) throws Exception { // Array of all Java keywords + true, false and null String keywordString -{"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const". "continue", "default", "do", "double", "else", "enum". "extends", "for", "final", "finally", "float", "goto", "1", "implementa", "import", "instanceof", "int", "interface", "long", "native","now", "package", "private", "protected", "public", "return", "short", "static", "atricttp", "super", "switch", "synchronized", "thia", "throw", "throwa", "transient", "try". "void", "volatile", "while": "true", "false", "null"); Set keywordSet = new HashSet(Arrays.asList(keywordString)); 0; int count = Scanner input = new Scanner(file); while (input hasNext()) { String word = input.next(); if (keywordSet.contains (word)) count++; 3 return count; 3 3 4. Question on Map, to be continued. Set keywordSet = new HashSet(Arrays.asList(keywordString)); 0; int count = Scanner input = new Scanner(file); while (input hasNext()) { String word = input.next(); if (keywordSet.contains (word)) count++; 3 return count; 3 3 4. Question on Map, to be continued

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions