How can i add the first to the following

String line = infile.readLine();
int linenum = 0;
while (line != null) {
int len = line.length();
linenum++;
System.out.println(linenum + "\t" + len);
line = infile.readLine();
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import java.text.*;
public class WordAnalyser extends JFrame implements ActionListener
// Menu items Open, Clear, Exit, WordCount, About
private JMenuItem jmiOpen, jmiClear, jmiExit, jmiWordCount, jmiAbout;
// Text area for displaying and editing text files
private JTextArea jta1, jta2;
// Status label for displaying operation status
private JLabel jlblStatus;
// File dialog box
private JFileChooser jFileChooser = new JFileChooser();
File infile;
File outfile = new File("OutFile.txt");
DecimalFormat numForm1 = new DecimalFormat("000");
DecimalFormat numForm2 = new DecimalFormat("0.00");
// Main method
public static void main(String[] args)
WordAnalyser frame = new WordAnalyser();
frame.setSize(500, 400);
frame.center();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public WordAnalyser()
setTitle("Word Analyser");
// Create a menu bar mb and attach to the frame
JMenuBar mb = new JMenuBar();
setJMenuBar(mb);
// Add a "File" menu in mb
JMenu fileMenu = new JMenu("File");
fileMenu.setMnemonic('F');
mb.add(fileMenu);
// Add a "Help" menu in mb
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
mb.add(helpMenu);
// Create and add menu items to the menu
fileMenu.add(jmiOpen = new JMenuItem("Open", 'O'));
fileMenu.add(jmiClear = new JMenuItem("Clear", 'C'));
fileMenu.addSeparator();
fileMenu.add(jmiExit = new JMenuItem("Exit", 'E'));
helpMenu.add(jmiWordCount = new JMenuItem("Word Count", 'W'));
helpMenu.add(jmiAbout = new JMenuItem("About", 'A'));
// Set default directory to the current directory
jFileChooser.setCurrentDirectory(new File("."));
// Set BorderLayout for the frame
getContentPane().add(new JScrollPane(jta1 = new JTextArea()), BorderLayout.CENTER);
getContentPane().add(jta2 = new JTextArea(), BorderLayout.EAST);
getContentPane().add(jlblStatus = new JLabel(), BorderLayout.SOUTH);
// Register listeners
jmiOpen.addActionListener(this);
jmiClear.addActionListener(this);
jmiExit.addActionListener(this);
jmiWordCount.addActionListener(this);
jmiAbout.addActionListener(this);
public void center()
// Get the screen dimension
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int screenWidth = screenSize.width;
int screenHeight = screenSize.height;
// Get the frame dimension
Dimension frameSize = this.getSize();
int x = (screenWidth - frameSize.width)/2;
int y = (screenHeight - frameSize.height)/2;
// Determine the location of the left corner of the frame
if (x < 0)
x = 0;
frameSize.width = screenWidth;
if (y < 0)
y = 0;
frameSize.height = screenHeight;
// Set the frame to the specified location
this.setLocation(x, y);
// Handle ActionEvent for menu items
public void actionPerformed(ActionEvent e)
String actionCommand = e.getActionCommand();
if (e.getSource() instanceof JMenuItem)
if ("Open".equals(actionCommand))
open();
else if ("Clear".equals(actionCommand))
clear();
else if ("Exit".equals(actionCommand))
System.exit(0);
else if ("Word Count".equals(actionCommand))
word_count();
else if ("About".equals(actionCommand))
JOptionPane.showMessageDialog(this,
"Program performs text analysis",
"About This Program",
JOptionPane.INFORMATION_MESSAGE);
// Open file
private void open()
if (jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION)
infile = jFileChooser.getSelectedFile();
open(infile);
// Open file with the specified File instance
private void open(File file)
try
// Read from the specified file and store it in jta
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
byte[] b = new byte[in.available()];
in.read(b, 0, b.length);
jta1.append(new String(b, 0, b.length));
in.close();
// Display the status of the Open file operation in jlblStatus
jlblStatus.setText(file.getName() + " Opened");
catch (IOException ex)
jlblStatus.setText("Error opening " + file.getName());
// Clear all display areas
private void clear()
jta1.setText("");
jta2.setText("");
jlblStatus.setText("");
// Perform word analysis with specified File instance
private void word_count()
int buff; // for reading 1 char at a time
int count = 0;
int sentences = 0;
int words = 0;
int chars = 0;
boolean start = true;
try
FileInputStream instream = new FileInputStream(infile);
FileOutputStream outstream = new FileOutputStream(outfile);
// convert FileOutputSream object to PrintStream object for easier output
PrintStream out = new PrintStream(outstream);
out.println("---Word Analysis---");
while ((buff=instream.read()) != -1)
switch((char)buff)
case '?': case '.': case '!':
if (start == false)
sentences++;
words++;
start = true;
break;
case ' ': case '\t': case '\n': case ',': case ';': case ':': case'\"': case'\'':
if (start == false)
words++;
start = true;
break;
default:
// 3-digit integer format
if (((char)buff >= 'a' && (char)buff<='z')||
((char)buff >= 'A' && (char)buff<='Z')||
((char)buff >= '0' && (char)buff <= '9')||
((char)buff == '-'))
chars++;
if ((words % 50) == 49)
if (start == true)
out.println();
out.print(numForm1.format(words+1) + " ");
out.print((char)buff);
start = false;
}// switch
}//while
instream.close();
out.println();
out.println();
out.println("Number of characters: " + chars);
out.println("Number of words: " + words);
out.println("Number of sentences: " + sentences);
out.print("Number of words per sentence: ");
// cast integers to float, then add 0.005 to round up to 2 decimal places
out.println(numForm2.format((float)words/sentences));
outstream.close();
try
//Read from the output file and display in jta
BufferedInputStream in = new BufferedInputStream(new FileInputStream(outfile));
byte[] b = new byte[in.available()];
in.read(b, 0, b.length);
jta2.append(new String(b, 0, b.length));
in.close();
catch (IOException ex)
jlblStatus.setText("Error opening " + outfile.getName());
catch (Exception e)
System.out.println(e);
}

Do you want to add the code
String line = infile.readLine();
int linenum = 0;
while (line != null) {
int len = line.length();
linenum++;
System.out.println(linenum + "\t" + len);
line = infile.readLine();
}to your rest of the program?

Similar Messages

  • How can i add two values under the same property?

    Hi all,
    How can i add two values under the same property name in a
    prop list? For example:
    [question1: "item1","item2", question2: "item3","item4"]
    To be more precise, i am creating a property list and I want
    whenever a two values have the same property name to be added int
    he list under the same property. For example:
    gMyList.AddProp (#""&question&"" & x,
    member("input").text)
    question is a variable that is updated fromt he user's input.
    Now, whenever somethign like this happens:
    question = "question1"
    member("input").text = "five"
    question = "question1"
    member("input").text = "six"
    I want to output list to be:
    [question1: "five","six"] and so on
    Any ideas?

    Maybe you could make each property a list (so you have a
    property list full
    of lists), and add multiple values to the list held in a
    particular
    property?
    Cheers
    Richard Smith

  • How can I add a contact on the calendar for an event

    How can I add a contact on the calendar for an event

    It is between Repeat and Alert on my iPhone 5 with iOS 6.0.1
    I used the + on the top right to add the event and when you look vertically starting with the name, followed by location and then time the rest of the default things includ Invitees, among other items. 

  • How can i add a MouseMotionlistener  to the cells in the JTable?

    hi !
    how can i add a MouseMotionlistener to the cells in the JTable?

    yes i have.but that is different from adding MouseMotionlistener to the cells for me .
    i just want get the values where the mouse moves to .

  • How can I add a word to the dictionary?

    How can I add a word to the dictionary on my iPhone 6 plus?
    Thanks.

    There's not an option to add a word to the dictionary. However, after typing that word several times, it will start to recognize it and offer it as a suggested word.

  • How can I add an iView to the Detailed Navigation itself

    How can I add an iView to the Detailed Navigation itself and hides the other hyperlinks?

    To add an iview on the Detailed navigation side of a page:
    1.Double click the page which brings up the page editor.
    2.Click the Display dropdown box and choose Dynamic Navigation.
    3.Add an ivew to it.Save and add the page to a role to see the results.
    if this is not u wanted, post back here.
    Regards.

  • How can I add new songs to the top (not the bottom) of my playlist in iTunes?

    How can I add new songs to the top of my playlist in iTunes?
    I thought thats what it did before but now it automatically adds new songs to the bottom of the list.
    Not a huge issue but an annoyance.

    Go to your Music library
    Then, Click Playlist
    Then, Click the sort arrow until it points down.

  • HT3387 When I use pages the languages that I mainly use are English and Hebrew. The spellchecker works for English but not with Hebrew. How can I add another language to the spellcheck?

    When I use pages the languages that I mainly use are English and Hebrew. The spellchecker works for English but not with Hebrew. How can I add another language to the spellcheck?

    http://m10lmac.blogspot.com/2011/06/extra-spell-checking-dictionaries-for.html

  • How can we add additional fields to the BP Search RESULT screen?

    Dear Experts,
    How can we add additional fields to the BP Search RESULT screen so that the BP's being displayed in a search result show maintained values for the particular column/field?
    Thanks!!!

    Hi Laxman,
                           I got same requirement for ibase hierarchy.I want to add new fields in Ibase hierarchy AB.Do you have any idea regarding this.My requirement is that ,i want to dispaly a fields as a check box which display that this component is in under warranty or not by checking the box.Plz tell ,how can i add a new field in tree type context node.I add a new fields using AET ,but that is not available in that AB.
    Thanks
    Vishwas Sahu
    Edited by: vishwas sahu on Nov 17, 2009 1:51 PM
    Edited by: vishwas sahu on Nov 18, 2009 5:22 AM

  • How can i add Custom fields into the

    Dear Experts
    We have Ecc6.0 system,
    How can i add Custom fields into the Infotype Screen(PA30),i heard that we do it by PM01 Tcode.
    But in PM01 i am unable to find the enhance infotype tab.
    How can i do it ....pls help.....
    Regards
    Sajid

    Hi,
    Do it thru the third tab : Single Screen.
    There write down the infotype number (e.g. 0022) and say generate objects.
    Regards,
    Dilek

  • How can I add sales TAX at the end of my calculations?

    How can I add sales TAX at the end of my calculations?

    We currently do not support adding sales tax.
    Randy

  • How can I add a linkbutton in the matrix (SBO 7.10.75)

    Hi ,everybody ,I want to add a linkbutton in a matrix ,and it's linkobject is If_PurchaseOder , but there are some errores ,and I don't know why .
    in the SBO2004B ,You can use
    set oLink=oColumn.ExtendedObject
    oLink.LinkObject=If_PurchaseOrder
    but in the SBO7.10.75 , oColunm has no such method.
    How can I do it ?
    thanks

    From the documentation of 2004a:
    Use the LinkedButton object to create a link to another object from a column with a link arrow.
    First, assign this object to a LinkedButton object and then use the LinkedButton object to link the column to the object you want.
    Example
    [Visual Basic] The following sample code shows how to add a column with a link arrow and link it using the ExtendedObject property.
    Dim oLink As SAPbouiCOM.LinkedButton
        Set oColumn = oColumns.Add("A", it_LINKED_BUTTON)
        oColumn.DataBind.SetBound("True","","linkDataSource")
        Set oLink = oColumn.ExtendedObject
        oLink.LinkedObject = lf_BusinessPartner

  • How can I add a logo to the bottom right of a video?  I have a jpg logo to use.

    How can I add a logo to bottom right of video, using a jpg?

    Even though David's answer is for Final Cut Express, the same answer should apply for FCP X only you would need to place the "track" ... let's say clip ... above the clip it is to overlay.  Thus it can either be a storyline or a connected clip but it should reside above the primary storyline assumming that is where the video is you want your logo to overlay.  As David points out, the type of graphic file should be one that allows the transparent background feature such as a PNG or PSD, etc.  Of course, if your logo has a solid box background, you may be able to simply scale it down and position it to the right place and overlay it over your other video clip using the method described above.  Hope this helps.
    stephen

  • How can I add jar files into the namespace in code?

    My friends:
    I need to add jar files into my namespace dynamicly in my code.But the jar files might be repeated, I am not sure.so, i wonder how can I add them into my namespace, ignoring the repeated files?
    This is my code:
    URL[] urlArrayA = new URL[5];
    urlArray[0] = sample1;
    urlArray[1] = sample2;
    URL[] urlArrayB = new URL[5];
    urlArrayB[0] = sample3;
    urlArrayB[1] = sample4;
    URLClassLoader urlClassLoaderA = URLClassLoader.newInstance(urlArrayA);
    URLClassLoader urlClassLoaderB = URLClassLoader.newInstance(urlArrayB);
    how can i visit classes in urlClassLoaderA from classes in urlClassLoaderB?

    could anyone please answer the question for me ? thank you...

  • How can I add left join in the coding

    I intend to dynamic add left jion in my java class.
    so I write the coding like below:
    incident_id = svc_yokyu_id(+)
    (Both of them have been selected in the select sentence.)
    However, when I run the app, it will throw a sql error.(ora-01416)
    then I copy the error sql sentence and try to test it
    QRSLT WHERE (incident_id = svc_yokyu_id(+))--this is a error sql sentence.
    Finding that if I delete the left join,(+), the sql will run right,
    or I modify the sql like
    QRSLT WHERE incident_id in (Select svc_yokyu_id from xxfm_srl_sr_jc_relation xssjr where incident_id = xssjr.svc_yokyu_id(+)) , it run right as well.
    according to bussiness requestion, I can't write the coding like above,
    so, i don't know how to implement it.
    and i hope to your advice. thx

    Does a hand come out of the screen, grabbing you by the wrist, every time you try?
    Just guessing…
    Peter

  • How can I add a linkbutton in the matrix (XML)

    Hi,Everybody ,I want to add a linkbutton in the matrix ,and the form that the matrix is in was created by using XML ,this is the XML code .
                                                      <column AffectsFormMode="1" backcolor="-1" description="" disp_desc="0" editable="1" font_size="12" forecolor="-1" right_just="0" text_style="0" title="ItemCode" type="16" uid="2" visible="1" width="80">
    <databind alias="U_ItemCode" databound="1" table="@IQM1"/>
                                                           <ExtendedObject linkedObject="4"/>
                                                      </column>
    and How can I do in my code , and I can get the linkbutton.
    thanks .

    Change the type of the column to 116 and then it will display the linked arrow.
    You'll see right now it has made space but not diplaying it.
    Hope this helps

Maybe you are looking for

  • Handheld application loader encountered a problem and needs to close

    This problem has been occurring for months for me now, and still, I have not found a solution. There used to be no problem. The solutions I found online including in this forum do not work for me.  I have uinstalled and reinstalled all bb softwares o

  • How to develop a tool to add my text automatically in the desired location in a pdf document

    I am trying to create an action in pdf just similar to "File name stamper" . Here I need to enter a text and save. and that saved text to be inserted  in the desired loction in my document.Manually entering text is time consuming. I want this to be a

  • Set iphoto pictures as dektop pictures

    Hi, I have pictures in my iphoto library but when I right click there is no set as dektop picture, how can I set a pictures in iphoto as dektop picture, can ypu help, thanks.

  • No more EXPORT (Share) into File

    Hi, without wanting to critizise iPhoto 6, actually, almost everything worked out without issues in my case, I am missing out on one function which I used on iPhoto 5 a lot. The SHARE to FILE function. I really used it a lot to convert a certain amou

  • Multiple SUs specifing different link types consuming same service

    Consider, SU1 and SU2 are deployed in C1 as part of SA1 and SA2 respectively. SU1 consumes S1,E1,"hard" SU2 consumes S1,E1,"soft" Now, C1 creates a ME specifying Address=<S1,E1> . The NMR doesn't know if C1 is "working on behalf of" SU1 or SU2. How d