Calculating words per minute

Hi, trying to write a typing tutor program.
Having trouble calculating the words per minute.
Does anyone know what Im doing wrong?
import java.awt.*;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.Component;
import java.awt.Container;
import java.awt.Font;
import java.awt.Image;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JLabel;
class TTutor extends JFrame{
    final JTextArea area= new JTextArea();
    final JTextField field = new JTextField(40);
    GridBagConstraints constraints = new GridBagConstraints();
    JLabel label = new JLabel();
    String[] phrase = { "In a world full of people",
               "Only some want to fly",
               "Isn't that crazy?"};
    int i = 0;
    int j = 0;
    int time = 0;
    double wps = 0;
    double wpm =0;
    int words= 0;
    int count = 0;
    public TTutor(){
     super("TTutor v1.0");
    void addGB (Component component, int x, int y){
     constraints.gridx = x;
     constraints.gridy = y;
     add(component, constraints);
    private void createAndShowGUI(){
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     setSize(600, 300);
     setLocation(200, 200);
     setLayout(new GridBagLayout());
     area.setFont(new Font("Serif", Font.PLAIN, 18));
     area.setText(phrase[0]);
     area.setEditable(false);
     addGB(area, 1, 0);
     field.addKeyListener(new KeyListener(){
          public void keyTyped(KeyEvent e){
              update(e);
              count++;
          public void keyPressed(KeyEvent e){
              if (e.getKeyCode() == KeyEvent.VK_LEFT){
               System.out.println("Left");
               e.consume();
          public void keyReleased(KeyEvent e){}
     Image image = Toolkit.getDefaultToolkit().getImage("keyboard.jpg");
     addGB(new ImageComponent(image), 1, 1);
     addGB(field, 1, 2);
     Timer timer = new Timer();
     TimerTask task = new TimerTask(){
          public void run(){
              time++;
              String clock = String.valueOf(time);
              System.out.println(clock);
              System.out.println(count);
              System.out.println(words);
              System.out.println(wps);
              System.out.println(wpm);
              //calculate the words per minute - Anyone have any ideas?
              try{
              words = count/5; //1 word = 5 characters
              wps = words/time;
              wpm = wps * 60;
              }catch(Exception e){System.out.println("error");}
              String Wpm = String.valueOf(wpm);
              label.setText("");
              repaint();
     timer.scheduleAtFixedRate(task, 1000,1000);
     addGB(label, 2, 2);
     setVisible(true);
     field.requestFocus();
    public void update(KeyEvent ke){
     char c = ke.getKeyChar();
     System.out.println("" + (int)c);
     try{
     if (field.getText().equals(area.getText())){
         phrase[j] = phrase[j++];
         area.setText(phrase[j]);
         field.setText("");
         i=0;
}catch(Exception e){System.out.println("error");}
     if (j == phrase.length){
     field.setText("");
     field.setEditable(false);
     area.setText("Finished");
     if (c == 8){
         ke.consume();
         System.out.println("Backspace consumed: "+ke.isConsumed());
         field.setText(area.getText().substring(0, i));
         return;
     if (i < area.getText().length()){
         char ac = area.getText().charAt(i);
         if (c == ac){
          System.out.println("match");
          i++;
         }else{
          System.out.println("no match");
          ke.consume();
     }else{
         ke.consume();
    public static void main (String[] args){
     java.awt.EventQueue.invokeLater(new Runnable(){
          public void run(){
              new TTutor().createAndShowGUI();
}Regards ABourke.

Does anyone know what Im doing wrong?http://www.catb.org/~esr/faqs/smart-questions.html
Now, before you take that the wrong way, please understand that the folks who answer questions here are volunteers. You're asking them to do a great deal of work just to figure out what problem you're having; not what the solution is, what the problem is. It's in your best interest to make your questions interesting and easy to answer. I can assure that few people will find copying, compiling, running, and playing detective just to figure out what trouble YOU are having is not likely to be easy to answer or interesting to anyone.
Please consider this carefully, google "SSCCE", and rephrase your question. Thanks!
~

Similar Messages

  • Calculating beat per minute

    Hello,
    I wrote a multichannel data acquisition code including Respiration ,ECG and GSR (Galvanic Skin Response). I want to calculate beat per minute and breathing rate. I�ve used a threshold peak detector. I�ve thought that the difference of the index of the first peak and th index of the second peak generates the number of total samples between two consecutive counts. To count the beat rate per second I divided sample rate by the number of samples per beat. Then I�ve multiplied beat rate per second by 60 to generate beat rate per minute. I also did the same thing for breath rate per minute.
    The problem is the result wasn�t successful. As you can see in the attachment I�ve calculated bpm as 253 and brpm is 538. BPM should be
    60 for a healthy person and BRPM should be 15.
    Ther is nothing wrong with my signals. But as you can see in the diagram data comes as #4 and difference between index of the first peak and the index of the second peak is quite high.
    What do you recommend me to do to calculate the correct values.
    Thanks
    Attachments:
    multichannel.JPG ‏89 KB
    diagram.JPG ‏100 KB

    Have a look on the attached vi.
    The first loop runs in 1 second, generating an array of 100 random numbers;
    The second loop calculates the sum of the array elements, and would run every 0.2 seconds.
    Except that the occurence nodes synchronize the calculation with the availability of the data array.
    You can experiment the effect of occurence by removing the nodes : the vi still runs, but the led blinks 5 times more rapidly.
    Last comment : don't forget the ultimate set occurence when exciting the first loop, otherwise the second loop will wait for ever...
    Ask if you need more help.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Synchro_loops.vi.zip ‏13 KB

  • Beats Per Minute Feature

    Hello,
    Well, I have quite a bit of acquired music through friend's CDs over the years, and when I saw this Beats Per Minute feature on iTunes, I freaked. I normally have to calculate it by myself, but to have a feature that will do this for me, I thought, is fantastic.
    So, I checked the option that allowed it to calculate the BPM of all my songs. I was estatic when I saw the numbers to the right. Unfortunately, it only calculated about 100 out of 2,000 songs. It stopped, right there. It would be great if it could have done them all.
    So, my question is, what went wrong where it stopped calculating all the BPMs of every song? Is there another option I have to check?
    Thanks for visiting this topic,
    And an even bigger thanks to those who give any reponse back.

    AFIK iTunes does not calculate BPM, but it does have a coulmn in the library where you can record a BPM value.
    So I suspect you are using an iTunes utility program such as listed here:
    http://www.mmartins.com/mmartins/bpmdetection/bpmdetection.asp
    Perhaps you could contact the supplier? Or maybe if you give the name someone will be able to help.

  • Connection fee - Charge on Per minute basis or Per...

    I am new and want to use Skype to call Fix and Mobile line, I find there is a connection fee. Does that charge on on Per minute basis or Per connection basic?
    Thanks,
    Jeff
    Solved!
    Go to Solution.

    Hi,
    A connection fee is charged when you use Skype Credit to call a mobile or landline. Connection fees are charged according to the currency set in your Skype account, and per call.
    For more information on how to find which connection fee applies to the country you are calling, visit:
    https://support.skype.com/faq/FA1050
    Connection fees are also subject to the following conditions:
    - If the call lasts less than one second, the call is not charged.
    - If the call lasts more than one second, the connection fee is calculated based on your account currency.
    - If your currency is not set, the connection fee will be calculated in Euros.
    - If your billing address is within the EU, the connection fee is subject to 15% VAT – so for example, the actual cost for a connection fee of €0.039 (the global rate) would be €0.045. However, since your Skype Credit has been subject to 15% VAT at the time of purchase, you would see the amount of €0.039 deducted from your Skype Credit.
    - If a call is declared to be free of charge (such as a promotion or 0800 number) the connection fee is not charged.
    - If you have one of our Unlimited subscriptions, the connection fee is not charged for the calls covered by the subscription.
    Hope this helps.
    Did my reply answer your question? Mark it as a solution to help others, Thanks.

  • Multiple charges for single text message, 10 cents per minute plan

    I have a Go Phone, 10 cents per minute plan, which shows text messages should be charged at 20 cents per msg. However, I am getting charged multiple times on each text message. The most recent was a message of approx 100 words, billed 4 times at 20 cents. AT&T Billing site shows four consecutive charges for this as a SMS Originating, Local message, each one 20 cents. Is my plan really 20 cents per message or is it a charge per number of characters, words, etc.?

    Hi  Thank you for your post!
    A standard text message or SMS is limited to 160 characters (including spaces and punctuation), so when sending a message longer than that, it actually gets broken up into however many 160 character massages it takes. In your case it sounds like there were 4 messages.
    Most phones will split and then combine messages together automatically when sending and receiving to keep their intended formatting, so it may not always be clear how many messages it actually takes. Many phones have a character counter built in to help with some of that confusion, it may need to be turned on in the settings.
    Please let us know if you have any other questions.
    Thanks,
    Dmitriy

  • Requests per minute in idle conditions in EM

    Hello Gurus,
    We are having an issue where in our Financial Reporting server is going down after throwing an Out of memory error in the logs in Weblogic.
    We have been monitoring the Financial Reporting service in the Weblogic console and in the Enterprise Manager to see the performance and have observed the following --
    - Initially the Heap free percent in the Financial Reporting server is staying at 70 - 80 percent for some time immediately after the services are started.
    - The heap free percent keeps on going down as the time proceeds.
    - The heap goes to 0 and ultimately the services goes into shutdown state in weblogic and becomes unaccesible.
    We also observed that the Financial Reporting service shows requests per minute to 80 in the env where we are facing this issue, however it is showing as 0 in the other env which are exact replica - http://s15.postimg.org/bt756hvuj/NEW_PROD_FR_in_Enterprise_Manager_Idle_Condition.png
    If someone can point us on what we need to check that would be great. as we are not sure as to why the request per minute will be around 80 in idle conditions.
    Any help will be highly appreciated.
    Thanks,
    hyperionEPM

    Sid_Middleware wrote:
    Hmmm... you can always try to boot up weblogic with more memory. Look at $DOMAIN_HOME/bin/setDomainEnv.cmd (or .sh in unix) and check for MEM_ARGS variable which specifies memory settings. Double the memory requirements and restart weblogic and see what happens.Increasing the memory is not a concern here, but the thing is that it keeps on going down even when our servers are idle.
    Also, what is Requests (per minute) as shown in the screenshot and do you know why the Requests (per minute) is showing around 80 even when there is no work going on?
    We have other environment which are again idle and the value is 0 there.
    Thanks,
    hyperionEPM

  • Throttling a file adapter to consume a max number of files per minute

    Is there a way to design a file adapter to throttle its processing bandwidth.
    A simple use case scenario is describes as follows;
    A File Adapter can only consumes a max of 5 files per minute. The producer average throughput is 3 files per minute but during peak times it can send 100 files per min. The peak times occur during end of year or quarterly accounting periods. If the consumer consumes more than 5 files per min the integrity of the environment and data is compromised.
    The SLA for the adapter is to :
    - Each file will be processed within 2 seconds.
    - Maximum File Transactions Per minute is 5
    An example is as follows.
    The producer sends 20 files to its staging directory within a minute. The consumer only processes 5 of these files in the first minute, sleeps then wakes up to consume the next 5 files in the second minute. This process is repeated until all files are processed.
    The producer can send another batch of files when ever it likes. So in the second minute the producer can send another 70 files. The consumer will throttle the files so it only processes 5 of these files every minute.

    Hi,
    If you have a polling frequency set to 2 secs..then controlling it to read only five files a min is difficult.?You can have the polling frequecy changed to 12secs
    or u can schedule a BPEL for every min and use synchronous read operation and loop it 5 times to read 5 files.

  • How do I count and display events every few seconds and then convert the counted values into events per minute? (for a heart rate monitor)

    Hi everyone,
    I'm building a heart rate monitor as a final year project with my lab partner using the NI USB-6009 and Labview 2009. We have managed to obtain a signal using a photo transciever, smooth it out and count the events, however the count is incremental.
    We wish to count the number of pulses we obtain for a few seconds (5-10 for example) and then use this value to obtain a pulse rate in beats per minute (e.g. 10 pulses in the first 10 seconds would give an estimated BPM of 60 etc etc).
    Does anybody have ides on how we could implement this? We have tried timed loops, elapsed time VI's and other things but nothing gives us what we need.
    Thanks in advance for any help that is offered.
    Jeshua Graham.

    We are very new to Labview. We are taking a raw signal from our DAQ and then using VIs to filter and then trigger counts on rising edges. I have attached our vi file to this post for you to look at (I hope that is what you mean by code).
    Attachments:
    TCRT-1010DAQ_jeshua1.vi ‏367 KB

  • How can i figure out the beats per minute of all the songs on my itunes list?

    I am a runner and would like to know the beats per minute of each song on my playlist.  Is there any app that is compatible with itunes so that I could get this information and easily upload it?

    The mentioned BeaTunes is nice... I've also used Tangerine.  You'll find that scanning one song with one app and scanning the same song with a different app will produce different results.  I'd just recommend being consistent and using the same app once you'd played with them to determine your favorite.
    Mixmeister also has a few different levels of software for DJ type stuff.

  • Not all BPM's (Beats Per Minute) from ID3 tags show in iTunes...

    I have a few thousand MP3's on my computer that I use for DJing, with Traktor software. The software analyzes the MP3 files to get the Beats Per Minute of the track, and then writes the ID3 information to the file.
    My problem is that in iTunes, only about 60% of the files' BPM's from the tags show up in the BPM column, and I'm not sure why. The rest just come up blank, even though I know for a fact that the BPM of the tracks is in the file (when I move the files to my 2nd machine and I ask Traktor to read the tags, all the info is there).
    Is there some kind of way to make iTunes re-read the ID3 tags so it'll finish the job?

    I used a program called beatunes with the same result. Beatunes will only call back BPM on songs I have loaded from CD's - not songs I have purchased thru itunes. Could be your issue too --- I will let you know if I find a resolution.

  • Spotlight crashing hundreds of times per minute

    On my new 13" Retina MBP, spotlight is crashing hundreds of times per minute, resulting in more or less complete CPU use by the crash reporter.
    The console logs are full of this:
    4/4/14 7:08:27.925 PM mdworker[22407]: (Fatal) Worker: Uncaught exception: 'NSInvalidArgumentException', reason: '-[__NSArrayM indexOfObjectWithOptions:passingTest:]: unrecognized selector sent to instance 0x7fea98409680'
    Stack: (0x7fff8703e244 0x7fff8bc28e75 0x7fff8704112d 0x7fff86f9c3f2 0x7fff86f9bf78 0x100964ea0 0x10096265b 0x7fff8f0ca899 0x7fff8f0ca72a 0x7fff8f0cefc9)
    Spotlight restarts itself and crashes again faster than once per second. I have to turn it off with launchctl. Trying to open one of the crash report logs from Console.app crashes Console.app, so that's good too.
    The issue seems to come and go. The machine will work for a while fine, then at some point I'll notice the fans have spun up. When I turn it back on later, sometimes it starts right back up, sometimes it works for a while.
    Really frustrating! I want spotlight back. I can't find anything about this on google. Any pointers?

    Back up all data.
    Triple-click anywhere in the line below on this page to select it:
    /.Spotlight-V100
    Right-click or control-click the line and select
    Services ▹ Open
    from the contextual menu.* A folder should open with an item selected. Move the selected item to the Trash. You'll be prompted for your login password. Restart the computer, empty the Trash, and test.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
    Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens (command-V). You won't see what you pasted because a line break is included. Press return.

  • In the new iOS-7 Safari, has the "reader" function been changed to eliminate the option to modify font size (and hence to modify the number of words per line), or is it just that I can't find how to do that?

    In the new iOS-7 Safari, has the "reader" function been changed to eliminate the option to modify font size (and hence to modify the number of words per line), or is it just that I can't find how to do that?

    iOS 7
    Seperate text size modification is no longer available in Safari Reafer.
    Use Settings.
    Settings >General > Text Size

  • With the new TC 2TB transfer data with Wire the speed is only 20kb per minute, can anybody help

    With the new TC 2TB transfer data with Wire the speed is only 20kb per minute, can anybody help ?
    The fist Backup use for 260GB 15hours!
    The Wifi ist Bridge configured.

    We are still learning the quirks and bugs of this new box..
    See the info here.. use accounts rather than disk or device password.. what happens.
    https://discussions.apple.com/thread/5146963?tstart=0

  • Why does firefox display one word per sentence

    firefox displays one word per sentence reading comments on www.zerohedge.com firefox is the only browser that does this Firefox has always done this reformat of the coments since day one why??

    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    *Use a compressed image type like PNG or JPG to save the screenshot
    *Make sure that you do not exceed the maximum size of 1 MB
    You can try these steps in case of issues with web pages:
    You can reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files.
    *Hold down the Shift key and left-click the Reload button
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Command + Shift + R" (Mac)
    Clear the cache and remove cookies only from websites that cause problems.
    "Clear the Cache":
    *Firefox/Tools > Options > Advanced > Network > Cached Web Content: "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Firefox/Tools > Options > Privacy > "Use custom settings for history" > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • What is the normal % per minute charge rate of the iPad (3rd generation)?

    Recently I've been experiencing some issues with the battery on my iPad. Even when plugged in to the charger, the battery goes down if I'm doing something processor intensive, and only charges at a rate of less than 1% per minute while in sleep mode. Has anyone else experienced this problem? Should I take it into the apple store?
    I first noticed it this morning when I left it on the charger all night and it was only at ~38% charge.

    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
     Cheers, Tom

Maybe you are looking for