diego_bravo13
2011-11-27 17:41:49 UTC
/JavaCS1/src/freqstudy/FreqStudy.java
/JavaCS1/src/freqstudy/WordCount.java
Your job is to write WordFreq, the heart of the application. It must extend Echo:
Echo.java
http://twiki-edlab.cs.umass.edu/bin/view/CS121Fall2011/PrSeven
(this shows the problem) i am having extreme difficulty, please help.
import java.util.*;
import java.io.*;
public class FreqStudy{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
System.out.println("enter file name");
String fileName = scan.next();
Scanner scan2 = new Scanner(System.in);
System.out.println("enter words to search for");
System.out.println("enter lower case, separated by spaces");
String wordString = scan2.nextLine();
WordFreq f = new WordFreq(fileName,wordString);
f.readLines();
f.reportFrequencies();
}
}
public class WordCount{
private String word;
private int count;
public WordCount(String w){
word = w;
count = 0;
}
public String getWord(){
return word;}
public int getCount(){
return count;}
public void incCount(){count++;}
public String toString() {
return(word + " --- " + count);
}
public boolean equals(Object other){
WordCount i = (WordCount)other;
return (this.word.equals(i.word));
}
}
import java.util.Scanner;
import java.io.*;
public class Echo{
String fileName; // external file name
Scanner scan; // Scanner object for reading from external file
public Echo(String f) throws IOException
{
fileName = f;
scan = new Scanner(new FileReader(fileName));
}
public void readLines(){ // reads lines, hands each to processLine
while(scan.hasNext()){
processLine(scan.nextLine());
}
scan.close();
}
public void processLine(String line){ // does the real processing work
System.out.println(line);
}
}