Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program will be based on developing a concordance for a file, where a concor

ID: 3797757 • Letter: T

Question

The program will be based on developing a concordance for a file, where a concordance is "an alphabetical list of the words (especially the important ones present in the file, usually with citations of the passages concerned You will create a graphical user interface for the user to specify the file to be processed and then compute the concordance of the file, removing stop words. The gui will have buttons to display the entire concordance or the concordance for a specified word. For each word, the display includes the total number of occurrences and for each occurrence, the line number in the file and the local context defined as the original line with the specified word in all upper case. Your program must be designed using functions, and you are to document the functions similar to javadoc, using Include in a comment at the beginning of your program, your name and a description of the main data structure used in your solution. Notes and Hints 75 Concordance: jingleBells tot For an open file object file obj.readlines0 will return a list, where each element is a Browse to File Display All Display word string, one of the lines of the file Remember that case should not matter ago: 1 here. The string "Dream" and "dream 19: A day or two AGO, should both count as the same word. bank: 1 Punctuation should be stripped so that 25 We got into a drifted BANK, bay: "dream." and "dream" both count as the 50 Just get a bob tailed BAY same word. bells 17 The context line printed should contain 5: BELLS on bob tail ring, its original capitalization (except for the 10 Oh, jingle BELLS, jingle BELLS specified word that is all upper case) and 14 Jingle BELLS, jingle BELLS original punctuation.

Explanation / Answer

import org.springframework.util.StringUtils;

/**
* Java program to count the number of occurrence of any character on String.
* @author Javin Paul
*/
public class CountCharacters {

  public static void main(String args[]) {
  
  String input = "Today is Monday"; //count number of "a" on this String.
  
  //Using Spring framework StringUtils class for finding occurrence of another String
  int count = StringUtils.countOccurrencesOf(input, "a");
  
  System.out.println("count of occurrence of character 'a' on String: " +

                " Today is Monday' using Spring StringUtils " + count);

  
  //Using Apache commons lang StringUtils class
  int number = org.apache.commons.lang.StringUtils.countMatches(input, "a");
  System.out.println("count of character 'a' on String: 'Today is Monday' using commons StringUtils " + number);
  
  //counting occurrence of character with loop
  int charCount = 0;
  for(int i =0 ; i<input.length(); i++){
  if(input.charAt(i) == 'a'){
charCount++;
  }
  }
  System.out.println("count of character 'a' on String: 'Today is Monday' using for loop " + charCount);
  
  //a more elegant way of counting occurrence of character in String using foreach loop
  
charCount = 0; //resetting character count
  for(char ch: input.toCharArray()){
  if(ch == 'a'){
charCount++;
  }
  }     
  System.out.println("count of character 'a' on String: 'Today is Monday' using for each loop " + charCount);
  }
  
  
}