Help to count number of words and time it

Hi,
I need help in inputting a text file using a file browser into a JTextArea and then count the number of occurance of each words in the file and display the time it takes in a JTextField.
Right now I am able to come up with the idea of creating an Array to list all the words but I am still unable to count them. And by extending an abstract class to create the array class. Below is attached my abstract class.
import java.io.*;
import java.util.Observable;
import java.util.StringTokenizer;
public abstract class AbstractWordCounter extends Observable
     /** Amount of time required to count words in the most recently read file. */
     protected long readTime;
     /** DELIMETERS used in this WordCounter */
     protected String DELIMETERS;
     /** By default, any AbstractWordCounter will have is delimeters set to any non-letter ASCII character */
     public AbstractWordCounter()
          this.readTime = -1;
          DELIMETERS = "";
          // Add any non-letter ASCII character to the list of tokens.
          for(int i = 0; i < 256; i++)
               if( !Character.isLetter( (char)i  ) )
                    DELIMETERS += Character.toString( (char)i);
     /** Get the delimeters used in this WordCounter */
     public String getDelimeters()
          return DELIMETERS;
     /** Change the delimeters used in this WordCounter
      * @param newDelimeters the new delimeters to be used
     public void setDelimeters(String newDelimeters)
          DELIMETERS = newDelimeters;
      *@return    The number of unique words in this WordCountItem object
     public abstract int getSize();
     /** @return  The total number of words counted by this WordCounter */
     public abstract int getTotalNumWords();
     /** Add a String to this WordCounter
      * @param s the String s is converted to lower-case.  If the lower-case String is already in the list, it's count is
      *        incremented.  Otherwise it is added to the list and its count is set to 1.
     public abstract void add(String s);
      * Get the ith WordCountItem
      *@param  i  must be between 0 and size - 1 (inclusive)
      *@return    The WordCountItem stored at the ith location
     public abstract WordCountItem getWordCountItem(int i);
      *  Clear this WordCounter.  After this method runs, this.size == 0.
     public abstract void clearCount();
     /** @return The amount of time (in milliseconds) that was required to read the most recent file */
     public long getReadTime()
          return this.readTime;
      *  Reads the file.  Converts each word in the file to lower case and adds it to this
      *  AbstractWordCounter.  The AbstractWordCounter is cleared before reading the new file.
      *  The time required to read the file and count the words is recorded.
      *@param  fileName  file to be opened.
      *@throws FileNotFoundException
     public final void readFile(String fileName) throws FileNotFoundException
          // Clear this AbstractWordCounter.  Open the file and count the words in the file.
}Then the time I have come up so far is in the class that extends the abstract class above and the code is as:
public long getReadTime()
          return this.readTime;
     }and I have a hard time to actually display this in a JTextField as it says non-static cannot be applied to a static content and if I change the method into static, another error of overiding the abstract occurs...
I am totally lost for these errors. And I am still unable to create a file browser to find a file. For now I just write a complete path to open the file.
would someone could point me the right direction for this problem... Thanks in advance

Crosspost: http://forum.java.sun.com/thread.jsp?forum=31&thread=521763&tstart=0&trange=15

Similar Messages

  • Need help to count number of rows and display in file

    Hello,
    my scenario is IDOC to File......i am using XSLT mapping and using FCC parameters to convert the flat file.
    now new requirement is i need to count number of rows and add count value last of the file.
    Please let me know how to do it,
    thanks in advance for your help.
    Regards,
    Chinna

    thanks again, one more Q.
    in XSLT mapping i have written for loop for complete structure.
    example : <Details>
                         <node1>
                         <node2>
                   </details>
    in XSLT mapping
                         <xsl:for-each select="ZMATMAS_01/IDOC/E1MARAM">
         <Details>
         </Details>
         </xsl:for-each>
    if i add the field at target side....then i will come under details node and it will be repeated.
    how to declare in XSLT mapping.

  • How to Count number of words in a file....

    Hi Experts,
    I have uploaded the text file, from the application server, like this: 
    call function 'GUI_UPLOAD'
      exporting
        filename = LV_ip_FILENAME
      tables
        data_tab = LT_FILETABLE.
    The text file contains some number character words....  like "sap labs india..... "
    Now, I wanted to count number of words in an internal table  LT_FILETABLE....  can anybody help me?

    Hi,
    Special Characters in Regular Expressions
    The following tables summarize the special characters in regular expressions:
    Escape character
    Special character Meaning
    Escape character for special characters
    Special character for single character strings
    Special character Meaning
    . Placeholder for any single character
    C Placeholder for any single character
    d Placeholder for any single digit
    D Placeholder for any character other than a digit
    l Placeholder for any lower-case letter
    L Placeholder for any character other than a lower-case letter
    s Placeholder for a blank character
    S Placeholder for any character other than a blank character
    u Placeholder for any upper-case letter
    U Placeholder for any character other than an upper-case letter
    w Placeholder for any alphanumeric character including _
    W Placeholder for any non-alphanumeric character except for _
    [ ] Definition of a value set for single characters
    [^ ] Negation of a value set for single characters
    [ - ] Definition of a range in a value set for single characters
    [ [:alnum:] ] Description of all alphanumeric characters in a value set
    [ [:alpha:] ] Description of all letters in a value set
    [ [:blank:] ] Description for blank characters and horizontal tabulators in a value set
    [ [:cntrl:] ] Description of all control characters in a value set
    [ [:digit:] ] Description of all digits in a value set
    [ [:graph:] ] Description of all graphic special characters in a value set
    [ [:lower:] ] Description of all lower-case letters in a value set
    [ [:print:] ] Description of all displayable characters in a value set
    [ [:punct:] ] Description of all punctuation characters in a value set
    [ [:space:] ] Description of all blank characters, tabulators, and carriage feeds in a value set
    [ [:unicode:] ] Description of all Unicode characters in a value set with a code larger than 255
    [ [:upper:] ] Description of all upper-case letters in a value set
    [ [:word:] ] Description of all alphanumeric characters in a value set, including _
    [ [:xdigit:] ] Description of all hexadecimal digits in a value set
    a f
          v Diverse platform-specific control characters
    [..] Reserved for later enhancements
    [==] Reserved for later enhancements
    u2192 More
    Special characters for character string patterns
    Special character Meaning
    Concatenation of n single characters
    {n,m} Concatenation of at least n and a maximum of m single characters
    {n,m}? Reserved for later enhancements
    ? One or no single characters
    Concatenation of any number of single characters including 'no characters'
    *? Reserved for later enhancements
    + Concatenation of any number of single characters excluding 'no characters'
    +? Reserved for later enhancements
    | Linking of two alternative expressions
    ( ) Definition of subgroups with registration
    (?: ) Definition of subgroups without registration
    1, 2, 3 ... Placeholder for the register of subgroups
    Q ... E Definition of a string of literal characters
    (? ... ) Reserved for later enhancements
    for more details please refer the following,
    [http://help.sap.com/abapdocu_70/en/ABENREGEX_SYNTAX_SIGNS.htm]
    [http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/902ce392-dfce-2d10-4ba9-b4f777843182?QuickLink=index&overridelayout=true]
    Thanks,
    Renuka S.

  • Help with converting hex to date and time

    Hi!
    I am using snmp4j libraries to walk the mib tree. The system date is getting returned in 11 hexadecimal octets. I require help in converting it to date and time. I looked up the RFC convention of what each octets represent. Require help with conversion.
    Eg: 07:db:06:0a:29:1d:00:2b:05:1e
    Thanks,

    Octets Contents Range
    1-2 year 0..65536
    3 month 1..12
    4 day 1..31
    5 hour 0..23
    6 minutes 0..59
    7 seconds 0..60
    (use 60 for leap-second)
    8 deci-seconds 0..9
    9 direction from UTC '+' / '-'
    10 hours from UTC 0..13
    11 minutes from UTC 0..59
    For example I just took the time an hour ago it came out as
    07:db:06:13:12:11:1a:00:2b:05:1e
    I have to convert this as a date long value to send it.
    Do I have to write an utility of my own to do it?

  • Program to count number of words

    I need some help with writing a program that counts the number of words in a file. Can anyone help me?

    I would try:
    read line
    save line to a string
    use split(" ") method from String to get each word
    into a String[]
    then put each entry in the array into a list
    repeat for all lines
    get size of listThat will only work for small-ish files. I would recommend using indexOf() until EOF is reached. You would need logic to ignore consecutive spaces and the like, but it should be both significantly smaller in memory footprint and faster in execution speed.
    - Saish

  • URGENT HELP NEEDED: counting number of particles from image

    this image on the left is showing particles
    hello i want to create a small VI that can count number of particles from a image that i load up. please see the attached image of particles and the VI printshot.
    I have used the tutorial "counting number of particles" but still the above VI does not work. it shows the number of particles = 1.. I do not know why it is doing so??
    I am not an expert in Labview so please can someone tell me where the problem is. sorry i could not attach the VI file itself but i have given an image of it..
    after anyone has solved this problem, i have to create a live system that will get live images from the camera - four frames every sec and the above VI has to count the
    number of particles for each frame and output to the user?? is this possible can anyone do it for me???
    p.s. in the above VI i read the image from file and count the number of particles. i do not do it to the binary image becuase the binary image is only a black screen
    when i run it
    thankyou

    Hi Farhan,
    Vision Assistant would be the best option to create some steps which you can then export to LabVIEW. You should try using the IMAQ Find Circles.vi. The attached image helps you find the number of circles of an image acquired from a camera. I have used the IMAQdx VIs in this example.
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies
    Attachments:
    vision.vi ‏59 KB

  • Powershell script to count number of list and library items in site collection

    We are identifying large lists in our 2010 SP environment and I'm attempting to write code to output the total number of list items in a site collection.   I'm using the code below but it only displays column data for title and url. 
    What do I need to add so it can count the number of items in each sharepoint list and library? 
    Get-SPSite -WebApplication http://sharepoint -Limit All |
       Select -ExpandProperty AllWebs |
       Select -ExpandProperty Lists |
       Select ParentWebUrl, Title
    I'm referencing
    http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts

    Please find belwo script, it will iterarte through all the folder/Subfoder to get the item counts from all list and library, you can modify this script to run this at site collection scope:
    Note: save the script in .ps1 file and execute the script as described below to get log file, it will save the log file out.txt in seleted directory:
    e.g.PS D:\PowershellScripts> .\ListItemCount.ps1 > out.txt
    $SPWebApp = Get-SPWebApplication "http://weburl.com/"
    foreach ($SPSite in $SPWebApp.Sites)
    if ($SPSite -ne $null)
    foreach ($SPWeb in $SPSite.AllWebs)
    foreach ($list in $SPWeb.Lists)
    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
    Write-Output $ListURL
    [Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
    #$query.Folder = fldr;
    #Recursive Scope....
    $query.ViewAttributes = "Scope='Recursive'"
    $allitems = $list.GetItems($query);
    $filecount = $allitems.Count;
    Write-Output " No of item: " $filecount
    if ($SPWeb -ne $null)
    $SPWeb.Dispose()
    if ($SPSite -ne $null)
    $SPSite.Dispose()
    You can update the code to get any specific list type item count, using if($list.BaseType -eq "DocumentLibrary") condition:
    if($list.BaseType -eq "DocumentLibrary")
    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
    Write-Output $ListURL
    [Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
    #$query.Folder = fldr;
    #Recursive Scope....
    $query.ViewAttributes = "Scope='Recursive'"
    $allitems = $list.GetItems($query);
    $filecount = $allitems.Count;
    Write-Output " No of item: " $filecount
    if ($SPWeb -ne $null)
    $SPWeb.Dispose()
    If my contribution helps you, please click Mark As Answer on that post and Vote as Helpful
    Thanks, ShankarSingh

  • Incrementing a string number for date and time

    There are probably a lot of ways to do this, but I only want to use a bunch of if - else loops if I really need to.
    I have a date and time for input, let's say 2006-04-19 22:00. In Java, if I convert that to 3 integers (year, month, day), it will output 2006-4-19. I need to be able to increment in a loop for every day and month from one date to the next. If I keep it as a string, I won't be able to increment the value though, (at least I'm not sure how). I'm thinking that even if I converted it to an integer and back to a string, that the leading zero would be removed.
    I found a post here that said something about formatting the number with 2 numbers, by using:
    DecimalFormat format = new DecimalFormat("00");
    format.format(1, sb, new FieldPosition(0));
    Or is there a way to use the gregorianCalendar stuff that would output the date with all of the zeros in place, while incrementing and looping correctly?
    Thanks.

    I would get a Date object--you can use java.text.SimpleDateFormat if you're starting with a String--and use that to create a GregorianCalendar. Then you can just call Calendar's add method to add one to whichever field you want. Use the SimpleDateFormat to turn the date back into a String for display again.
    Calculating Java dates: Take the time to learn how to create and use dates
    Working in Java time: Learn the basics of calculating elapsed time in Java
    Formatting a Date Using a Custom Format
    Parsing a Date Using a Custom Format

  • Need help for Flash quiz with score and timer

    Greetings, I need to urgently create a flash
    game with 10 questions, 3 answers per question. At the end of the
    quiz I need to get the time the quiz was completed for, what answers the player answered correctly and the time its completed into a database, + a couple of fields like name and phone that the user fills also needed to be added into db with the score and time. I need it by the end of tomorrow and I do realise i dont have the knowledge to make it, So if there is anyone that wishes to help or trade services I can give you back the favour by creating some html/css/web design content for you. Thanks in advance and please excuse me for my terrible english.

    download flash cs6 and use it to publish your ad or expand flash cc's publishing capabilites.  if you have a flash cc subscription you can download and use flash cs6 after logging into your cc acount.
    here's how to expand publishing capabilites of flash cc: http://forums.adobe.com/message/5511080#5511080#5511080

  • Search Bill for Phone Number. Date and Times?

    Hello-
    I am having a problem doing a search over the past 12 months for an individual number.
    Is there a quick and easy way to display the dates and times that I've placed a call to one specific number over the past 12 months?
    Thank you!

    YPP wrote:
    I was hoping for a way to search online and get a line by line display of dates for the calls made.
    If I have to download each pdf into a spreadsheet, combine them and do a search it will take a considerable amount of time.
    To reinforce Spiral's suggestion, if you go to the Usage Details tab you can download your data in csv format. Granted, downloading 12 files and stitching them together isn't as convenient as an online search. However, it's much easier to do this with csv downloads than it would be if you had to do the pdf-to-spreadsheet conversion yourself. And once you've pieced things together, the data are a lot of fun to play with.

  • Counting number of errors and generating a report

    Hi All
    I am fairly new to PL/SQL and I have a bit of a problem that I can't work out.
    What I need to do, is take a file that has a 6-digit store code, and a corresponding date, that indicates that the store made a particular error on that date. That table only has 2 columns, the STOREID and ERRORDATE. If a particular store did not make the error, they will not be included in this table.
    This table is provided to me monthly, .CSV format which i can import and place in a table with no problems.
    I also have another "master" table that contains a list of all the store codes, and their corresponding name & address details, so something like MASTERID (number), STORENAME, ADDRESS1, ADDRESS2, ADDRESS3 ( all varchar2(200)). STOREID will be included somewhere in the MASTERID column.
    I need to check each store and see if it has made the error. If it has, it needs to be placed in a table which is then used to issue an error noice. The part I'm finding difficult, is that if the store has made the same error in the past 3 months, it needs to be placed in a table so it can be issued a 'second notice' and if it has made the error twice previously in the past 6 months it needs to be placed in another table to be issued a 'final notice'.
    So I somehow need to keep track of which stores have made the error for the past 6 months and then check against it to see if it should be a first, second or third notice. I thought of using another table, call it HISTORY, with the columns STOREID and ERRORDATE, which indicates the store id code and the date the error was made
    The way I thought of doing it was to use the MASTERID column from the master detail table, and check each store code against the provided monthly file (STOREID). If it is in there, check the past 6 month history, count the number of previous errors and issue the notice accordingly IE-
    Store code is in the monthly file but not found in the previous 6 months in HISTORY - first notice, put store code and date into HISTORY table
    Store code is in the monthly and found ONCE in the previous 6 months in HISTORY - second notice, put store code and date into HISTORY table
    Store code is in the monthly file and TWICE in the previous 6 months in HISTORY - third notice, put store code and date into HISTORY
    Store code is in the monthly file and THREE+ times in the past 6 months in HISTORY - put store code into a table for further action, put store code and date into HISTORY
    If anyone could help it would be appreciated! I will be using this in Application Express, just as an anonymous pl/sql block, and I really am not sure how to do it.
    Importing and exporting .CSV files from tables is not an issue, that part I can do.
    The versions are ApEx 3.0.1 and Oracle 10g 10.2
    Thanks
    Bill

    As Frank said, please provide us some sample data else refer
    WITH T1 AS
    SELECT 'SRT1' STORE_ID, 'ER1' ERROR_CD FROM DUAL UNION ALL
    SELECT 'SRT2' STORE_ID, 'ER6' ERROR_CD FROM DUAL UNION ALL
    SELECT 'SRT1' STORE_ID, 'ER5' ERROR_CD FROM DUAL UNION ALL
    SELECT 'SRT3' STORE_ID, 'ER9' ERROR_CD FROM DUAL UNION ALL
    SELECT 'SRT1' STORE_ID, 'ER60' ERROR_CD FROM DUAL UNION ALL
    SELECT 'SRT2' STORE_ID, 'ER10' ERROR_CD FROM DUAL
    T2 AS
    SELECT COUNT(ERROR_CD) OVER (PARTITION BY STORE_ID)CNT_ERR,T1.*
    FROM   T1
    SELECT DECODE(CNT_ERR,1,'FIRST_NOTICE',2,'SECOND_NOTICE',3,'FINAL_NOTICE') NOTICE, T2.*
    FROM T2;*009*

  • How to count number of words in a string?

    Is it only possible by counting the number of white spaces appearing in the string?

    Of course that also depends upon how accurate you need to be and what the string contains. It is completely possible that there might be a line break which doesn't have a trailing or leading space.
    Like that.
    In that case Flash's representation of the string is likely "...space.\n\nLike that.." In chich case "space.\n\nLike" will be a word.
    Also if you split on space and there are places where there are two spaces in a row you could inflate your number. So somthing that changes newlines (and returns) to spaces, then removes any multiple spaces in a row, and finally does the split/count thing would be more accurate.
    But it all depends upon what you need.

  • HELP!!! remote desktop and time capsule

    Hello!
    Could You help me? I have two problems with access to my Time Capsule.
    I have wireless network at home based on Time Capsule, with one static IP. I have conected it (wireless) with two iMac's. Me and my girlfriend we have also two macbooks and when we are out of home we want to acces data on our Time Capsule disk. I need access to disk to edit data on it while being long way out of home. Second problem is to access data on our iMac's. I bought Apple Remote Desktop software, it's incredible what it can do . But only when I'm connected to my wireless network LAN. I need to controll my iMac while being out of home. How to configure Time Capsule and ARD to acces disk and control iMac's? Let me remind You that I have one static IP for Time Capsule router WAN. Please help and I would be very very thankful for screenshots of configuraion, I'm newbie in this.
    Thank You very much.
    Kind regards.
    Adam Milwiw-Baron

    The subject of connecting via ARD over the internet has been covered many times on these forums, and info on which ports to forward on your router are in the ARD user guide.
    See this article: http://www.starklmc.com/ard It should get you started, but you'll need to consult the documentation that came with your Time Capsule on setting up port forwarding correctly.

  • Help!! count the number of words in one line

    the question is that use JOptionPane and Array to count the number of words and characters that user inputed.
    for example, if I enter the " this is a java program"
    that messages have display 5 and 18.
    please show me the a completely program.
    thx!!!!

    You guys are heartless. Even you weren't born with programming knowledge hard-coded into your brain. Even you had to start from zero. Even you had to struggle at something in your life. In this spirit, I think that we should give this poor student a break and try to help him as much as possible. Here, try out my program, and perhaps it will give you some ideas for your own:
    public class WordCountingHomework
      public static void main(String[] args) throws InterruptedException
        String input = JOptionPane.showInputDialog("Please enter a String");
        // get your String and split the String into words
        // This will allow you to count words easily
        String[] strArray = new String(wordCountByteArray).split(" ");
        int delay = 400;
        for (;;)
          // loop through the array to count the words
          for (String string : strArray)
            System.out.print(string + " ");
            Thread.sleep(delay);
          System.out.println();
          delay *= 7;
          delay /= 10;
      private static byte[] wordCountByteArray =
        0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x64, 0x6f, 0x20, 0x79, 0x6f,
        0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x61, 0x72, 0x6b, 0x69,
        0x6e, 0x27, 0x20, 0x68, 0x6f, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b, 0x21
    }

  • How do you get a word and character count of a document in Pages for Mavericks

    How do you get a word and character count of a document in Pages for Mavericks?

    Hi jonathan,
    I struggled with this one as well, as i'm finishing up a PhD thesis and word counts are incredibly important. Through trial and error i found out that words like 'e.g.' and 'i.e.' count as two words and an ampersand (&) doesn't count at all. That being said, i didn't like the fact that the word count always included footnotes and i was dismayed that i couldn't get an accurate count of words in the main body of my text. That all disappeared yesterday when, by chance, while i was copying a completed chapter and pasting it into my main document, i discovered that Pages can indeed give you an accurate word count excluding the footnotes!  Here's all you need to do:
    1. In pages 5.2, make sure that the Word Count function is first enabled by selecting View --> Show Word Count from the Pages Menu Bar. (If it's already enabled, it will read View --> Hide Word Count, so if that's what it says, then no need to do anything.)
    2. Once enabled, check the Word count that's currently showing at the bottom of the page. That's the word count including your footnotes.
    2. Now, place your cursor anywhere within the current document, then hit command+A (for Select All).
    3. Viola! Your word count now shows the actual number of words within the body of the text only, excluding footnotes!
    Hope that helps!

Maybe you are looking for