A StringBot reads text files.
It performs a variaty of operations on the data it finds.
These are the operations:
Once the counting is done, it display the results.
Yes, StringBots are weird creatures!
Now, can you fill the blanks in the following program:
public static void main(String[] args){
String[] fileContents = getFileContents();
int loveCount = getWordCount(fileContents, "love");
int otherCount = getOtherCount(fileContents)
displayResults(loveCount, otherCount);
}
public static int getWordCount( wordList, String word){
int count = 0;
for(int i = 0; i<wordList.; i++){
if(wordList[].equals(word)){
count = count + 1;
}
}
return count;
}
public static getOtherCount(String[] wordList){
int count = 0;
for(int i = 0; i<wordList.length; i++){
if(.equals("love") && .equals("hate")){
count = count + 1;
}
}
return ;
}
A SmartStringBot can do everything that a StringBot can do.
However, it also has an additional behaviour.
It can search for a word in the array and return the index of that word if found, or -1 if not found.
Using a Linear Search algorithm, implement this behaviour.
A SuperStringBot can do everything that a StringBot can do.
However, it also has another additional behaviour.
It can determine which word is last alphabetically and return it. For example, in the sample file above, the SuperStringBot would return wrath.
Research the String family's compareTo function and implement this additional behaviour.
String classprivate length() contains() substring(int) substring(int, int) equals(String) !equals(String)