Search code examples
javareal-timeformulawords

Calculate Words Per Minute in real time


Alright so I've tried to research some formulas on how to calculate words per minute, I couldn't find anything. I'm trying to use the current formula to calculate the words per minute (It is currently inside a thread):

errors = numberOfIncorrectCharacters();
int wordsCount = (int)(typingArea.getText().length()/5);  
int newWPM = (int)(wordsCount/seconds)-(errors*2);  
if(newWPM >= 0){
    WPM = newWPM;  
}

(seconds: I have a timer that executes every 1000 MS and than increments seconds by 1 everytime it does.)

And then I'm painting the variable WPM to the screen. But it's definitely not working correctly. If anyone can help me with a formula to calculate the words per minute in realtime, it would be very appreciated. Thanks for any help you offer.


Solution

  • This code looks like words per second. So you need minute.

    float minute = (float)seconds/60;