Editing main method to test a method

205
January 29, 2018, at 3:06 PM

I am trying to test my method below. The code was provided and my task is to edit the main method so it will count the number of occurrence of the word in the file. Ignore cases in the word and possible punctuation and symbols in the file include , ! . ; : ? & # and $.

The question is that when i run it as is, it returns "The" and "Hello". it is supposed to return the number of times the word "the" appears in a txt file (in this case an "article"). I was told that i only had to alter lines in the main method.

This is what i have:

import java.io.*;
import java.util.*;
public class WordCount{
    public static String symbols="!,.;:?&#$";
    public static void main(String[] args){
        String[] ori={"The,","Hello:"};
        for(int i=0; i<ori.length; i++){
            String c=""+ori[i].charAt(ori[i].length()-1);
            if(symbols.indexOf(c)!= -1)
            ori[i]=ori[i].substring(0,ori[i].length()-1);
        }
        for(int i=0; i<ori.length; i++) {
        System.out.println(ori[i]);
    }

    public static int countWord(String word, File fileName) throws 
    FileNotFoundException{
        int count=0;
        Scanner input=new Scanner(fileName);
        while(input.hasNext()){
            String data=input.next();
            String c=""+data.charAt(data.length()-1);
            if(symbols.indexOf(c)!= -1)
                data=data.substring(0,data.length()-1);
            if(word.equalsIgnoreCase(data))
                count++;
        }
        return count;
    }
}
Rent Charter Buses Company
READ ALSO
Using setFill with a variable?

Using setFill with a variable?

I'm trying to pass a variable in Java, I need help getting it to work, I've included all relevant code below, there's threejava file's i'm working with

216
How to set AlertDialog button font color in Kotlin

How to set AlertDialog button font color in Kotlin

I know to setup font color in Java of AlertDialog button we can do like

516
Could java library &#39;colt&#39; replace with python library &#39;numpy&#39;? How is the performance of colt?

Could java library 'colt' replace with python library 'numpy'? How is the performance of colt?

I don't really like implement models using python, but numpy is really goodThus currently I'm seeking an equivalent of numpy in java and somebody recommended 'colt'

205