Should get you started.
public class TextAnalyser {
private String inputString;
public TextAnalyser(String inputString) {
this.inputString = inputString;
}
public int numChars(){
return inputString.length();
}
public String getInputString() {
return inputString;
}
public void addTextToInputString(String text) {
inputString += text; //prefer string builder
}
public void clear() {
inputString = null;
}
public int frequencyOf(char c) {
int count = 0;
for(int x = 0; x < inputString.length(); x++) {
if(inputString.charAt(x) == c) {
count++;
}
}
return count;
}
public double percentageOf(char c) {
return ((double)frequencyOf(c) / (double)inputString.length()) * 100D;
}
//public char mostFrequent(){
//}
}
I haven't added any null checks ect but i hope this helps.