Hi all
ive just recently started learning java and was happy to find a forum that may be able to give me a little assistance. I have been set an excersize to create a filter processor that relays information between several filters to give a result. I have created one of the filters already, however i need the filter processor working in order to test wether the filter i have done works correctly. However im not completely sure where to start with it, i know that i have to import scanner and use tokenizing within the code but where exactly to start is whats giving me some trouble. Here is the excersize question ive been given
Write a FilterProcessor class. It should accepts a Filter object in its constructor.
It should also have a go() method.
This method should read from standard input, break the input into words
(space/newline separated) and pass each word to the filter.
The string returned by the filter should be printed to the console.
The go() method should stop when it sees the word “end”.
It should then print the number of words processed.
I have the code for input scanner in there already but im not sure how to use tokenizing to suit the task. eg
public Set<String> getInput()
{ System.out.prin t("> ");
String inputLine =
reader.nextLine ().trim().toLow erCase();
String[] wordArray = inputLine.split ("[\\s]+");
Set<String> words = new HashSet<String> ();
for (String word : wordArray) {
words.add(word) ;
}
return words;
}
any help watsoever would be greatly appreciated!
ive just recently started learning java and was happy to find a forum that may be able to give me a little assistance. I have been set an excersize to create a filter processor that relays information between several filters to give a result. I have created one of the filters already, however i need the filter processor working in order to test wether the filter i have done works correctly. However im not completely sure where to start with it, i know that i have to import scanner and use tokenizing within the code but where exactly to start is whats giving me some trouble. Here is the excersize question ive been given
Write a FilterProcessor class. It should accepts a Filter object in its constructor.
It should also have a go() method.
This method should read from standard input, break the input into words
(space/newline separated) and pass each word to the filter.
The string returned by the filter should be printed to the console.
The go() method should stop when it sees the word “end”.
It should then print the number of words processed.
I have the code for input scanner in there already but im not sure how to use tokenizing to suit the task. eg
public Set<String> getInput()
{ System.out.prin t("> ");
String inputLine =
reader.nextLine ().trim().toLow erCase();
String[] wordArray = inputLine.split ("[\\s]+");
Set<String> words = new HashSet<String> ();
for (String word : wordArray) {
words.add(word) ;
}
return words;
}
any help watsoever would be greatly appreciated!
Comment