viewing paste Unknown #40440 | Java

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
 
public class Program {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int uncorrectedErrors = 0;
 
        String textSample = "Lorem ipsum dolor sit amet";
        String[] partsSample = textSample.split(" ");
 
        System.out.println(":: TYPING TEXT ::\n" + textSample);
 
        long start = System.currentTimeMillis();
 
        String text = scanner.nextLine();
        String parts[] = text.split(" ");
        int length = text.length() - 1;
 
        long end = System.currentTimeMillis();
 
        for (int i = 0; i < partsSample.length; i++) {
            if (! partsSample[i].equals(parts[i])) {
                uncorrectedErrors++;
            }
        }
 
        double time = TimeUnit.MILLISECONDS.toSeconds(end - start);
        time = time / 60;
 
        double grossWPM = (length / 5) / time;
        System.out.println("Gross WPM: " + grossWPM);
 
 
        double netWPM = grossWPM - (uncorrectedErrors / time);
        System.out.println("Net WPM: " + netWPM);
    }
}
 
Viewed 854 times, submitted by Guest.