Reading in a text file

For my next project I'm supposed to read in a text file and then compute the legibility index. How do I go about reading in a text file?

You should check your double equal signs in that procedure....
Also, the logic you posted above (which I followed), doesn't work perfectly for calculating the number of syllables...for instance, the word "Romeo" contains 3 syllables, but the program will only count two...basically some words which contain the vowels 'io' and 'eo' sometimes are 1 syllable and sometimes are 2....but my program does come close to the indexes listed on the website you mentioned.
Anyways, here is what I have for a very hackish approach (not modularized, but I don't have time to fix it I'm, I'm off work soon).
import java.io.*;
import java.util.*;
public class LegibilityProfiler
   public static void main(String[] args)
      new LegibilityProfiler();
   public LegibilityProfiler()
      String line,thisWord;
      String[] words;
      int numSentences = 0;
      int numWords = 0;
      int numSyllables = 0;
      int syl,consecutiveVowels,i,j = 0;
      boolean isWord=false;
      char lastvowel=' ';
      try
         BufferedReader reader = new BufferedReader(new FileReader("input.txt"));
         //read through lines until end of file is reached
         while ((line = reader.readLine()) != null)
            //split the words up by spaces
            words = line.split("\\s+");
            //add number of words in the line just read to total count
            numWords+=words.length;
            //process each word in this line
            for(i=0;i<words.length;i++)
               //initialize variables used for each word
               syl=0;               //number of syllables in this word
               isWord=false;        //if "word" contains letters
               thisWord="";         //stores only the letters in current word
               consecutiveVowels=0; //number of consecutive vowels
               lastvowel=' ';       //last vowel processed
               //process the word
               for(j=0;j<words.length();j++)
//if word contains character that completes a sentencce
if(words[i].charAt(j) == '.' ||
words[i].charAt(j) == ':' ||
words[i].charAt(j) == ';' ||
words[i].charAt(j) == '?' ||
words[i].charAt(j) == '!')
numSentences++;
//for each character in the word, extract only the letters
if(Character.isLetter(words[i].charAt(j)))
isWord=true;
thisWord+=words[i].charAt(j);
//process only the letters from current word to count vowels
for(j=0;j<thisWord.length();j++)
if(isVowel(Character.toLowerCase(thisWord.charAt(j))))
//if it's the first vowel in a sequence, increase syllable
if(consecutiveVowels==0)
syl++;
//either way, increase consecutive vowel count
consecutiveVowels++;
//store last vowel read in
lastvowel=thisWord.charAt(j);
else //not a vowel, so make sure count is 0
consecutiveVowels=0;
/* once word is processed check to make sure the word didn't
end with an e, and have no other vowels right before it
if(consecutiveVowels==1 && (lastvowel=='e' || lastvowel=='E'))
syl--;
//if it was a word, increase syllable count
if(isWord)
if(syl==0)
syl=1;
numSyllables+=syl;
System.out.println("Number of Words: "+numWords);
System.out.println("Number Sentences: "+numSentences);
System.out.println("Number of Syllables: "+numSyllables);
double ri=206.835-(84.6*numSyllables/numWords)-(1.015*numWords/numSentences);
System.out.println("\nReadability Index: "+((int)ri));
reader.close();
catch(IOException e)
e.printStackTrace();
public boolean isVowel(char c)
return (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c=='y');

Similar Messages

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • Reading from a text file into a 2D array

    How do you read from a text file and put it into a 2D array? Or if someone could guide me to where I can find the information?

    This tutorial shows how to read a file:
    http://java.sun.com/docs/books/tutorial/essential/io/scanfor.html
    This tutorial shows how to create arrays with multiple dimensions:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

  • HOW TO WRITE AND READ FROM A TEXT FILE???

    How can I read from a text file and then display the contents in a JTextArea??????
    Also how can I write the contents of a JTextArea to a text file.
    Extra Question::::::: Is it possible to write records to a text file. If you have not idea what I am talking about then ignore it.
    Manny thanks,
    your help is much appreciated though you don't know it!

    Do 3 things.
    -- Look through the API at the java.io package.
    -- Search previous posts for "read write from text file"
    -- Search java.sun.com for information on the java.io package.
    That should clear just about everything up. If you have more specific problems, feel free to come back and post them.

  • How to read from a text file one character at a time?

    Hello
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Lavi 

    lava wrote:
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Some additional comments:
    You really don't want to read any file one character at a time, because it is highly inefficient. More typically, you read the entire file into memory with one operation (or at least a large chunk, if the file is gigantic) and then do the rest of the operations in memory.  One easy way to analyze it one byte at a time would be to use "string to byte array" and then autoindex into a FOR loop, for example.
    Of course you could also read the file directly as a U8 array instead of a string.
    Message Edited by altenbach on 06-10-2008 08:57 AM
    LabVIEW Champion . Do more with less code and in less time .

  • Reading in a text file to GUI for later analysis

    Good Morning any and everyone,
    I'm trying to get a piece of code working to read in a text file and it isn't working very well. The code has been seriously crunched together from a multitude of sources so I suspect that the error has occurred from there.
    The errors that are occurring are "Can't Find Symbol" errors. Only 2 of them though which is a lot less than I had earlier. Now I'm just banging my head against the wall.
    Has anyone got any suggestions as to where I'm going wrong? Anything greatly appreciated.
    (PS> Please be gentle, I'm still a newbie)
    Thanks.
    import java.util.*; // required for List and ArrayList
    import java.io.*; // required for handling and IOExceptions
    import javax.swing.*;
    public class textAnalyser extends JFrame // implements ActionListener
        // the attributes
        // declare a TextArea
        private JTextArea viewArea = new JTextArea(10,55);
        // declare the menu components
        private JMenuBar bar = new JMenuBar();
        private JMenu fileMenu = new JMenu("File");
        private JMenu quitMenu = new JMenu("Quit");
        private JMenuItem selectChoice = new JMenuItem("Select");
        private JMenuItem runChoice = new JMenuItem("Run");
        private JMenuItem reallyQuitChoice = new JMenuItem("Really quit");
        private JMenuItem cancelChoice = new JMenuItem("Cancel");
        // declare an attribute to hold the chosen file
        private File chosenFile;
        // the constructor
        public textAnalyser()
            setTitle("Text Analyser"); // set title of the frame
            add(viewArea); // add the text area
            // add the menus to the menu bar
            bar.add(fileMenu);
            bar.add(quitMenu);
            // add the menu items to the menus
            fileMenu.add(selectChoice);
            fileMenu.add(runChoice);
            quitMenu.add(reallyQuitChoice);
            quitMenu.add(cancelChoice);
            // add the menu bar to the frame
            setJMenuBar(bar);
            // add the ActionListeners
    //        selectChoice.addActionListener(this);
    //        runChoice.addActionListener(this);
    //        reallyQuitChoice.addActionListener(this);
    //        cancelChoice.addActionListener(this);
            // configure the frame
            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            setSize(450,200);
            setVisible(true);
         public void actionPerformed(ActionEvent e)
                   if(e.getSource() == displayContentsChoice)
                        try
                             final int MAX = 300;
                             FileReader textFile = new FileReader("textfile.txt");
                             BufferedReader textStream = new BufferedReader(textFile);
                             int ch; // holds integer value of character
                             char c; // holds character when type cast from integer
                             int counter = 0; //counts number of characters read
                             ch = textStream.read(); //reads the first character from the file
                             c = (char) ch; //type cast from integer to character
                             viewArea.append("\n");
                             /*     continue through the file until either the end of the file or the maximum
                             number of characters allowed have been read*/
                             while(ch != -1 && counter <= MAX)
                                       counter++; // increment the counter
                                       viewArea.append("" + c); // display the character
                                       ch = textStream.read(); // read the next character
                                       c = (char) ch;
                             textStream.close();
                             viewArea.append("\n");
                   catch(IOException ioe)
                             if(chosenFile == null) // no file selected
                                       viewArea.append("No file selected\n");
                             else
                                  viewArea.append("There was a problem reading the file\n");
    }          

    A couple of points:
    *You've commented out stuff that is needed, like the adding of actionlisteners, the implements actionlistener,...
    *Your actionlistener is looking for a menu choice which doesn't exist  "displayContentsChoice".  Does this menu item need to be created?
    *How much of this code have you yourself created?  Do you understand its inner working?
    *What is the purpose of this code?  Is it for work?  School?  Homework?
    Good luck!
    /Pete

  • Getting repeated values when reading from a text file.

    I need to read from a text file. When the token encounters a particular word (command) I need to read the next line and perform some actions. However, this part is working but it is repeating the values again and again until it encounters the next particular word (command). Hope that someone will help me out, as always when I posted a problem in these forums.
    SetOperations class - contains the set methods
    // Imported packages.========================================================
    import java.util.Vector;
    import java.util.Iterator;
    // Public class SetOperations.===============================================
    public class SetOperations
         // Instance variables.===================================================
         private Vector v = null; // Creates new instance of vector.
         protected int memberCount;
         // Constructor.==========================================================
         public SetOperations()
              v = new Vector();
         } // end constructor.
         // Method isMember.======================================================
         * Checks whether the element is already a member of the set.
         * @return True if Vector v contains Object member.
         public boolean isMember(Object member)
              if (member != null) // only if Object member is not null.
                   return v.contains(member); // returns true if vector already contains member.
              else
                   return false; // returns false if vector does not contain member.
         } // end public boolean isMember(Object member).
         // Method addMember.=====================================================
         * Adds a member to the set.
         * @return Adds Object member to Vector v.
         public void addMember(Object member)
              //if (! v.contains(member)) // only if element is not already a member.
              if (isMember(member) == false) // only if element is not already a member.
                   v.add(member); // adds a member.
         } // end public void addMember(Object member).
         // Method countMember.===================================================
         * Returns the number of members present in the vector.
         * @return Number of elements present in the vector.
         public int countMember()
              return v.size();
         } // end public int countMember().
         // Method isSetEmpty.====================================================
         * Returns true if set is empty.
         * @return True if no elements are present in Vector v.
         public boolean isSetEmpty()
              return v.size() == 0; // returns 0 if no elements are present in the vector.
         } // end of public boolean isSetEmpty().
         // Method printMember.===================================================
         * Displays member/s of the set.
         * @return Prints element/s present in the vector.
         public void printMember()
              for (int i = 0; i < v.size(); i++) // iterates through present members.
                   System.out.println("[" + i + "] " + v.get(i)); // displays member/s present in the vector.
         } // end of public void printMember().
    } // end public class SetOperations.
    SetTextLauncher class - reads from a text file and implements the set operations
    // Imported packages.========================================================
    import java.util.*;
    import java.io.*;
    // Public class SetTestLauncher.=============================================
    public class SetTestLauncher
         // Main method public static void main(String args[]).===================
         public static void main(String args[])
              displayFile("test.txt"); // outputs result from text file.
         // method to display a file on screen
         public static void displayFile (String textFile)
              // Instance variables.===============================================
              // Creates new instances of SetOperations.
              SetOperations setA = new SetOperations();
              SetOperations setB = new SetOperations();
              SetOperations setC = new SetOperations();
              SetOperations setD = new SetOperations();
              SetOperations setE = new SetOperations();
              // Initialisation.
              String line = "", nextLine = "";
              FileReader fr = null;
              try
                   // Opens the file with the FileReader data sink stream.
                   fr = new FileReader(textFile);
                   // Converts the FileReader input stream with the BufferedReader processing stream.
                   BufferedReader br = new BufferedReader(fr);
                   // Iterates through text file reading lines until end of text lines.
                   while (line != null)
                        line = br.readLine(); // reads one line at a time.
                        if(line == null) break; // when the line is null break the loop.
                        // Creates a new instace of StringTokenizer.
                        StringTokenizer st = new StringTokenizer(line);
                        // Loops until there are no more tokens.
                        while (st.hasMoreTokens())
                             String token = st.nextToken(); // reads next token.
                             // Only if the token encounters the String "membera".
                             if(token.equals("membera"))
                                  nextLine = br.readLine(); // gets next line.
                                  setA.addMember(nextLine); // adds a member to the set.
                                  // Displays members present in the set if vector is not empty.
                                  if (! setA.isSetEmpty())
                                       setA.printMember(); // print members present.
                                  // Displays the number of member/s present in the vector.
                                  System.out.println("Number of set members: " + setA.countMember());
              // Catches and displays exceptions.
              catch (FileNotFoundException exp)
                   System.out.println(exp.getMessage());
                   exp.printStackTrace();
              catch (IOException exp)
                   System.out.println(exp.getMessage());
                   exp.printStackTrace();
              finally
                   try
                        // if file is found
                        if (fr != null)
                             // close file
                             fr.close();
                   catch (IOException exp)
                        exp.printStackTrace();
         } // end public static void main(String args[]).
    } // end public class SetTestLauncher.

    Thanks for your interest. Please ignore SetOperations class, it is just the class containing the methods and it works correctly since I checked it without reading from a text file. I marked the part where I think lies my problem in class SetTestOperations.
    The information in the text file is as follows:
    membera
    Hillman
    membera
    Skoda
    membera
    Honda
    membera
    Toyota
    and the result is:
    [0] Hillman
    Number of set members: 1
    [0] Hillman
    [1] Skoda
    Number of set members: 2
    [0] Hillman
    [1] Skoda
    [2] Honda
    Number of set members: 3
    [0] Hillman
    [1] Skoda
    [2] Honda
    [3] Toyota
    Number of set members: 4
    instead of just one set:
    [0] Hillman
    [1] Skoda
    [2] Honda
    [3] Toyota
    Number of set members: 4
    Hope it is easier to understand like this.
    Regards
    Marco
    I need to read from a text file. When the token
    encounters a particular word (command) I need to read
    the next line and perform some actions. However, this
    part is working but it is repeating the values again
    and again until it encounters the next particular
    word (command). Hope that someone will help me out,
    as always when I posted a problem in these forums.
    SetOperations class - contains the set
    methods
    // Imported
    packages.=============================================
    ===========
    import java.util.Vector;
    import java.util.Iterator;
    // Public class
    SetOperations.========================================
    =======
    public class SetOperations
    // Instance
    e
    variables.============================================
    =======
    private Vector v = null; // Creates new instance of
    f vector.
         protected int memberCount;
    Constructor.==========================================
    ================
         public SetOperations()
              v = new Vector();
         } // end constructor.
    // Method
    d
    isMember.=============================================
    =========
    * Checks whether the element is already a member of
    f the set.
         * @return True if Vector v contains Object member.
         public boolean isMember(Object member)
    if (member != null) // only if Object member is not
    ot null.
    return v.contains(member); // returns true if
    if vector already contains member.
              else
    return false; // returns false if vector does not
    not contain member.
         } // end public boolean isMember(Object member).
    // Method
    d
    addMember.============================================
    =========
         * Adds a member to the set.
         * @return Adds Object member to Vector v.
         public void addMember(Object member)
    //if (! v.contains(member)) // only if element is
    is not already a member.
    if (isMember(member) == false) // only if element
    nt is not already a member.
                   v.add(member); // adds a member.
         } // end public void addMember(Object member).
    // Method
    d
    countMember.==========================================
    =========
    * Returns the number of members present in the
    e vector.
         * @return Number of elements present in the vector.
         public int countMember()
              return v.size();
         } // end public int countMember().
    // Method
    d
    isSetEmpty.===========================================
    =========
         * Returns true if set is empty.
    * @return True if no elements are present in Vector
    r v.
         public boolean isSetEmpty()
    return v.size() == 0; // returns 0 if no elements
    ts are present in the vector.
         } // end of public boolean isSetEmpty().
    // Method
    d
    printMember.==========================================
    =========
         * Displays member/s of the set.
         * @return Prints element/s present in the vector.
         public void printMember()
    for (int i = 0; i < v.size(); i++) // iterates
    es through present members.
    System.out.println("[" + i + "] " + v.get(i)); //
    // displays member/s present in the vector.
         } // end of public void printMember().
    } // end public class SetOperations.
    SetTextLauncher class - reads from a text file
    and implements the set operations
    // Imported
    packages.=============================================
    ===========
    import java.util.*;
    import java.io.*;
    // Public class
    SetTestLauncher.======================================
    =======
    public class SetTestLauncher
    // Main method public static void main(String
    g args[]).===================
         public static void main(String args[])
    displayFile("test.txt"); // outputs result from
    om text file.
         // method to display a file on screen
         public static void displayFile (String textFile)
    // Instance
    ce
    variables.============================================
    ===
              // Creates new instances of SetOperations.
              SetOperations setA = new SetOperations();
              // Initialisation.
              String line = "", nextLine = "";
              FileReader fr = null;
              try
    // Opens the file with the FileReader data sink
    ink stream.
                   fr = new FileReader(textFile);
    // Converts the FileReader input stream with the
    the BufferedReader processing stream.
                   BufferedReader br = new BufferedReader(fr);
    // Iterates through text file reading lines until
    til end of text lines.
                   while (line != null)
    line = br.readLine(); // reads one line at a
    at a time.
    if(line == null) break; // when the line is null
    null break the loop.
                        // Creates a new instace of StringTokenizer.
                        StringTokenizer st = new StringTokenizer(line);
                        // Loops until there are no more tokens.
                        while (st.hasMoreTokens())
    String token = st.nextToken(); // reads next
    next token.
    // Only if the token encounters the String
    tring "membera".
                             if(token.equals("membera"))
                                  // *****THE PROBLEM LIES HERE....I GUESS
    // need to read the next line after encountering the word membera in text file
    nextLine = br.readLine(); // gets next line.
    setA.addMember(nextLine); // adds a member to
    ber to the set.
    // Displays members present in the set if
    set if vector is not empty.
                                  if (! setA.isSetEmpty())
                                       setA.printMember(); // print members present.
    // Displays the number of member/s present in
    ent in the vector.
    System.out.println("Number of set members: " +
    s: " + setA.countMember());
              // Catches and displays exceptions.
              catch (FileNotFoundException exp)
                   System.out.println(exp.getMessage());
                   exp.printStackTrace();
              catch (IOException exp)
                   System.out.println(exp.getMessage());
                   exp.printStackTrace();
              finally
                   try
                        // if file is found
                        if (fr != null)
                             // close file
                             fr.close();
                   catch (IOException exp)
                        exp.printStackTrace();
         } // end public static void main(String args[]).
    } // end public class SetTestLauncher.

  • How to read in a text file of race lap times....

    How do i read in a text file containing lap times from a race for one driver?
    I have the times down 1 column and look like this.
    I then want to add the times up to get a total race time. I have been looking at the Calendar class and the simpleDateFunction but not sure how to go about it.
    1'43.857
    1'37.860
    1'38.147
    1'37.922
    1'37.662
    1'37.639
    1'37.621
    1'37.728
    1'37.508
    1'37.990
    1'38.114
    1'38.177
    1'38.162
    1'37.847
    1'38.013
    1'38.196
    1'37.963
    1'37.924
    1'38.038
    1'37.962
    Thanks
    Trev

    Considering that your times have non-numerical chars you have no choice but to read them as Strings. Once you have done that you will need to parse the times yourself, ie spilt it into the three separate bits of data. Then you can use the Calendar class if you wish or you can keep a running tally yourself. Just don't forget to tick over seconds when milliseconds reaches 999 and tick over minutes when seconds reach 59.

  • Read in a text file and parse at spaces

    I need to read in a text file, then split it at the spaces (after each word)
    then I would like to save each sentence (maybe as a String Buffer)
    (chek each word to see if a .?! is at the end to determine the end of a sentence)
    Then I need to add the word END to the end of the StringBuffer
    then store each sentence as an element in an arrayList.
    Please Help.

    Cant you just store the entire text file into a really big String, then split it at each "."?
    String text = "";
    //read file into text
    String[] sentences = text.split(".");

  • Is it possible to read/write to text file without deleting it?

    I know how to read from a text file and how to write to a text file. The problem that i have is i need to use a text file to store data for my application to read and also for my application to write. I would like it if i could write two programs really, one reads, the other is used to update the text file. This file is a list of verbs. I thought about using databases but i couldn't get them to work. I downloaded MySQL server 5.0 and installed it. I then downloaded the driver from http://www.mysql.com/products/driver and ran the auto installer. it said everything worked out perfectly but when i try these lines:
    Class.forName("com.mysql.jdbc.Driver");
    I get a SQLException that says no suitible driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    ( I thought this driver came with the JDK but i guess not, i just read about it in a java book)
    I get a ClassNotFoundException
    that just says sun.jdbc.odbc.JdbcOdbcDriver
    So yeah, SQL is pretty much not working. I need a solution to my problem, either by using text files, or a different type of database. I heard you could use excel to create a database but i have no idea how and i hear microsoft access could also do this, however i don't have microsoft access and i don't intend on paying for it. So, here are my questions:
    1st, is there a tutorial on using excel databases in java programs
    (if not)
    2nd is there a way to read/write/update a text file without deleting it?
    (if not)
    3rd is there a way to get SQL working, i have windows vista this could be the problem
    (if not)
    4th what could i do to store information on the hd for reading and modifying later?
    thanks, lateralus

    A database might be overkill just for a list of words.
    Thoughts:
    <ul>
    <li>What is the extent of your "file updating"? If you are just appending to the file, opening it in append mode will keep the file from being clobbered.</li>
    <li>Otherwise, why not create new files instead of editting them? The file names could include a version number or timestamp, allowing the reader to select the newest one.
    </li>
    </ul>

  • How to read the whole text file lines using FTP adapter

    Hi all,
    How to read the whole text file lines when error occured middle of the text file reading.
    after it is not reading the remaining lines . how to read the whole text file using FTP adapter
    pls can you help me

    Yes there is you need to use the uniqueMessageSeparator property. Have a look at the following link for its implementation.
    http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28994/adptr_file.htm#CIACDAAC
    cheers
    James

  • Reading of a text file in J2ME

    Hi,
    I have a problem with the reading of a text file:
    String conn = "file:///root1/formazione.txt";
    FileConnection file = (FileConnection)Connector.open(conn,Connector.READ);
    InputStream is = null;
    if(filecon2.exists()) {
    DataInputStream dis = file.openDataInputStream();
    dis.readUTF());
    Error is:
    java.io.EOFException
    at java.io.DataInputStream.readFully(+48)
    at java.io.DataInputStream.readUTF(+30)
    at java.io.DataInputStream.readUTF(+4)
    at mainPackage.FileReader.run(+597)
    Must I read byte and change it in String?

    How did you write the file? Did you use writeUTF?
    Try reading the file through a normal read, read() or read(byte[])

  • Help with reading in a text file and arrays

    I need to read in a text file with info like this for example
    dave
    martha
    dave
    billy
    I can read the information into an array and display the names but what I need to do is display how many times the same name is in the file for example the output should be
    dave 2
    martha 1
    billy 1
    How can I accomplish this? Would I use a Compareto Method to find
    duplicate names?

    Hi,
    I would recommend storing them in a Hashtable.. something like this:
    Hashtable names = new Hashtable() ;
    String s ;
    while( ( s = bufferedReader.readLine() ) != null ) {
        if ( names.contains( s ) ) {
           names.put( s , new Integer( names.get(s)+1 ) ) ;
        else {
           names.put( s , new Integer( 1 ) ) ;
    }Then the hashtable will contain a set of keys and values, which are the names and counts respectively.
    Kenny

  • Reading through a text file and then sorting

    I'm having a lot of problems with this.
    I have to read through a text file and I have to split the string up so that it is seperated into individual tokens. A line from the text file looks like this. addEvent(new Bell(tm + 9000)). I have to grab the addEvent, new, Bell, tm and 9000 and store it in a linkedlist. After reading through the whole text file I have to sort the the linked list based on the number. ie: 9000. Is there any way to do this? I currently break up the text file using a StringTokenizer object but then i am uncertain on how to add it to a linked list and then sort each line based on the number. Any help would be appreciated.
    Joe

    Sorry to bother you Ben but I just can't get my head wrapped around this. Here is exactly what I have to do:
    After reading, Events must be stored in the EventSet according to the time they are to occur. Assume that no time number is more than 8 digits long. Restart() must be able to deal appropriately with any order of the Events. To accomplish this have Restart() save the relevant Event information in an LinkedList of strings and sort the Events by time before adding each event to EventSet. Use the <list>.add() to set up your linked list. This is shown in c09:List1.java and Collections.sort(<list>) shown in c09:ListSortSearch. Modify the Bell() to output a single "Bing!". When you read in a Bell event generate the appropriate number of Bell events as indicated by rings. These must be set to the correct times. This is an alternative to generating the new Bell events within Bell(). It will allow them be sorted into their correct time sequence. At this point the output of the program should be identical the original program.
    After the intitial start, when restarting Restart() must provide to the user the option to recreate the EventSet from the linked list or read in a new file (supplied by the user). This must be achieved by prompting the user at the console. Please also allow the user the option to quit the program at this stage.
    Main Program Code:
    public class GreenhouseControls extends Controller
    private boolean light = false;
    private boolean water = false;
    private String thermostat = "Day";
    private boolean fans = false;
         private class FansOn extends Event
              public FansOn(long eventTime)
                   super(eventTime);
              public void action()
              // Put hardware control code here to
              // physically turn on the Fans.
              fans = true;
              public String description()
                   return "Fan is On";
         private class FansOff extends Event
              public FansOff(long eventTime)
                   super(eventTime);
              public void action()
              // Put hardware control code here to
              // physically turn off the Fans.
              fans = false;
              public String description()
                   return "Fans are Off";
         private class LightOn extends Event
              public LightOn(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here to
                   // physically turn on the light.
                   light = true;
              public String description()
                   return "Light is on";
         private class LightOff extends Event
              public LightOff(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here to
                   // physically turn off the light.
                   light = false;
              public String description()
                   return "Light is off";
         private class WaterOn extends Event
              public WaterOn(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   water = true;
              public String description()
                   return "Greenhouse water is on";
         private class WaterOff extends Event
              public WaterOff(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   water = false;
              public String description()
                   return "Greenhouse water is off";
         private class ThermostatNight extends Event
              public ThermostatNight(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   thermostat = "Night";
              public String description()
                   return "Thermostat on night setting";
         private class ThermostatDay extends Event
              public ThermostatDay(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   thermostat = "Day";
              public String description()
                   return "Thermostat on day setting";
         // An example of an action() that inserts a
         // new one of itself into the event list:
         private int rings;
         private class Bell extends Event
              public Bell(long eventTime)
                   super(eventTime);
              public void action()
                   // Ring every 2 seconds, 'rings' times:
                   System.out.println("Bing!");
                   if(--rings > 0)
              addEvent(new Bell(System.currentTimeMillis() + 2000));
              public String description()
                   return "Ring bell";
         private class Restart extends Event
              public Restart(long eventTime)
                   super(eventTime);
              public void action()      
                   long tm = System.currentTimeMillis();
                   // Instead of hard-wiring, you could parse
                   // configuration information from a text
                   // file here:
              try
              BufferedReader in = new BufferedReader(new FileReader("Event Config.txt"));
              String str;
                   String[] l1 = new String[5];
                   LinkedList l2 = new LinkedList();
              while((str = in.readLine()) != null )
                        StringTokenizer st = new StringTokenizer(str, "(+); ");
                        int nIndex = 0;
                        while (st.hasMoreTokens())
                             l1[nIndex] = st.nextToken();
                        //System.out.println(st.nextToken());
                             nIndex++;
                        l2.add(l1);
                   String[] s1 = (String[])l2.get(1);
                   for(int i = 0; i < s1.length; i++)
                        System.out.println(s1);
                   Comparator comp = s1[4];
                   Collections.sort(l2, comp);
              in.close();
              catch (IOException e)
    rings = 5;
    addEvent(new ThermostatNight(tm));
    addEvent(new LightOn(tm + 1000));
    addEvent(new LightOff(tm + 2000));
    addEvent(new WaterOn(tm + 3000));
    addEvent(new WaterOff(tm + 8000));
    addEvent(new Bell(tm + 9000));
    addEvent(new ThermostatDay(tm + 10000));
    // Can even add a Restart object!
    addEvent(new Restart(tm + 20000));*/
    public String description() {
    return "Restarting system";
    public static void main(String[] args) {
    GreenhouseControls gc =
    new GreenhouseControls();
    long tm = System.currentTimeMillis();
    gc.addEvent(gc.new Restart(tm));
    gc.run();
    } ///:~
    Examples File:
    addEvent(new ThermostatNight(tm));
    addEvent(new Bell(tm + 9000));
    addEvent(new Restart(tm + 20000));
    addEvent(new LightOn(tm + 1000));
    addEvent(new WaterOn(tm + 3000));
    rings = 5;
    addEvent(new FansOn(tm + 4000));
    addEvent(new LightOff(tm + 2000));
    addEvent(new FansOff(tm + 6000));
    addEvent(new WaterOff(tm + 8000));
    addEvent(new WindowMalfunction(tm + 15000));
    addEvent(new ThermostatDay(tm + 10000));
    EventSet.java Code:
    // This is just a way to hold Event objects.
    class EventSet {
    private Event[] events = new Event[100];
    private int index = 0;
    private int next = 0;
    public void add(Event e) {
    if(index >= events.length)
    return; // (In real life, throw exception)
    events[index++] = e;
    public Event getNext() {
    boolean looped = false;
    int start = next;
    do {
    next = (next + 1) % events.length;
    // See if it has looped to the beginning:
    if(start == next) looped = true;
    // If it loops past start, the list
    // is empty:
    if((next == (start + 1) % events.length)
    && looped)
    return null;
    } while(events[next] == null);
    return events[next];
    public void removeCurrent() {
    events[next] = null;
    public class Controller {
    private EventSet es = new EventSet();
    public void addEvent(Event c) { es.add(c); }
    public void run() {
    Event e;
    while((e = es.getNext()) != null) {
    if(e.ready()) {
    e.action();
    System.out.println(e.description());
    es.removeCurrent();
    } ///:~
    Event.java Code
    abstract public class Event {
    private long evtTime;
    public Event(long eventTime) {
    evtTime = eventTime;
    public boolean ready() {
    return System.currentTimeMillis() >= evtTime;
    abstract public void action();
    abstract public String description();
    } ///:~
    Is this problem easier than I think it is? I just don't know what to add to the linkedList. A LinkedList within a linkedList? I find this problem pretty difficult. Any help is muchly appreciated.
    Joe

  • Reading Tab Delimited Text File

    HI
    I am having problem in reading Tab Delimited text file.
    If i place some spaces in name of text file. it dosn`t read the file.
    if there is a simple name without space, then it reads easily.
    but when having space in file name then it shows nothing.
    PLZ help me .......
    give me some code or links to solution
    thanks!

    Could you post up an example of the file? With a FedEx report file, I created an application to read each line and split the String into an array where ever a [tab] exists. Since the columns aren't evenly tabbed, I used a regular expression to replace any whitespace in a with a \t (tab). Now it takes that line and splits it into an array where the [tab] exists. Then I access that specific column in the String by line.
    08/28/2007                        FedEx Ground                             COLO2
    23:16:29                        LANE FULL REPORT                  reptClaneFulls
                                                                              Page 1
                          Next               Sorters
                          Load         Main            Auto Smalls
                 Chute    Point  Primary  Secondary  Primary  Secondary
                 0101     8001         0         11        0          0
                 0102     5333         0          9        0          0
                 0104     0142         0        441        0          0
                 0106     0328         0          5        0          0
                 0107     0452         0          2        0          0
                 0110     0333         0          2        0          0
                 0113     0447         0          7        0          0
                 0114     0447         0          1        0          0
                 0115     0303         0         11        0          0
                 0127     0132         0          2        0          0
                 0128     0132         0         11        0          0
                 0129     0132         0          9        0          0
                 0130     0405         0        102        0          0
                 0131     0371         0        270        0          0
                 0132     0371         0        168        0          0
                 0133     0122         0         13        0          0
                 0134     0456         0         36        0          0
                 0135     0146         0        152        0          0
                 0136     0146         0          2        0          0
                 0138     0371         0         24        0          0
                 0201     0552         0          9        0          0
                 0204     0445         0         69        0          0
                 0205     0445         0         51        0          0
                 0207     0641         0          1        0          0
                 0211     0551         0          1        0          0
                 0212     0454         0          7        0          0
                 0213     3441         0         39        0          0
                 0216     0841         0          1        0          0
                 0217     0631         0        211        0          0
                 0222     0441         0         12        0          0
                 0223                  0          5        0          0
                 0224     0441         0          9        0          0
                 0225     0441         0         42        0          0
                 0226     0441         0         11        0          0
                 0227     0441         0          5        0          0
                 0229     0619         0        753        0          0
                 0230     0619         0        188        0          0
                 0231     0602         0          2        0          0
                 0232     0604         0         91        0          0
                 0233     0604         0          3        0          0
                 0238     0601         0          1        0          0
                 0304     1435         0         12        0          0
                 0307     2430         0        477        0          0
                 0309     1430         0         98        0          0
                 0310     1430         0          1        0          0
                 0311     0971         0          1        0          0
                 0312     0449         0         19        0          0
                 0313     0449         0        128        0          0
                 0315     0923         0         31        0          0
                 0316     0981         0         11        0          0
                 0317     0972         0          9        0          0
    08/28/2007                        FedEx Ground                             COLO2
    23:16:29                        LANE FULL REPORT                  reptClaneFulls
                                                                              Page 2
                          Next               Sorters
                          Load         Main            Auto Smalls
                 Chute    Point  Primary  Secondary  Primary  Secondary
                 0318     0972         0          6        0          0
                 0319     2431         0          1        0          0
                 0323     0436         0          9        0          0
                 0324                  0          3        0          0
                 0326     3431         0         12        0          0
                 0328     0958         0         55        0          0
                 0332     0430         0         84        0          0
                 0333     0430         0         16        0          0
                 0334     4430         0         29        0          0
                 0337     0480         0          2        0          0
                 0343     0555         0         36        0          0
                 0405     1437         0         52        0          0
                 0406     1437         0         51        0          0
                 0407     3152         0         58        0          0
                 0408     3152         0          2        0          0
                 0410     0152         0          5        0          0
                 0411     0152         0          3        0          0
                 0415     0100         0         55        0          0
                 0417     0253         0         95        0          0
                 0420     0282         0          1        0          0
                 0421     0282         0         82        0          0
                 0422     0753         0         13        0          0
                 0425     0165         0          9        0          0
                 0426     0165         0          8        0          0
                 0427     0089         0         21        0          0
                 0428     0089         0         10        0          0
                 0434     0437         0          3        0          0
                 0436     0170         0          4        0          0
                 0441     0263         0          9        0          0
                 0442     0219         0          1        0          0
                 0443     0219         0         20        0          0
                 0444     3258         0          3        0          0
                 0447     0156         0         89        0          0
                 0448     0156         0         59        0          0
                 0449     0156         0          1        0          0
                 0450     0760         0         14        0          0
                 0451     3163         0         16        0          0
                 0453     0212         0         27        0          0
                 0454     7760         0          2        0          0
                 107A     0219         0          0        0         88
                 108A     0219         0          0        0         89
                 110A     7061         0          0        0        185
                 111A     7061         0          0        0        190
                 112A     0170         0          0        0          3
                 113A     0170         0          0        0          1
                 114A     0170         0          0        0          3
                 118A     0089         0          0        0        261
                 119A     0089         0          0        0        255
                 120A     0282         0          0        0          5
                 121A     0282         0          0        0          4
                 122A     0753         0          0        0          6
    08/28/2007                        FedEx Ground                             COLO2
    23:16:29                        LANE FULL REPORT                  reptClaneFulls
                                                                              Page 3
                          Next               Sorters
                          Load         Main            Auto Smalls
                 Chute    Point  Primary  Secondary  Primary  Secondary
                 124A     3156         0          0        0        258
                 125A     0258         0          0        0         74
                 126A     3258         0          0        0          3
                 127A     0263         0          0        0         34
                 128A     3263         0          0        0          7
                 129A     0152         0          0        0         39
                 130A     0152         0          0        0         44
                 131A     0152         0          0        0         33
                 132A     3152         0          0        0        176
                 133A     3152         0          0        0        181
                 134A     0253         0          0        0         34
                 135A     0253         0          0        0         34
                 136A     3253         0          0        0        103
                 137A     0156         0          0        0         85
                 138A     0156         0          0        0         87
                 139A     0437         0          0        0        271
                 140A     3437         0          0        0        111
                 141A     0165         0          0        0        204
                 142A     3165         0          0        0          5
                 143A     0163         0          0        0          9
                 144A     3163         0          0        0          5
                 147A     7760         0          0        0          9
                 201A     8001         0          0        0          1
                 202A     8001         0          0        0          2
                 205A     3435         0          0        0         62
                 206A     0402         0          0        0        218
                 208A     0405         0          0        0         15
                 212A     0411         0          0        0          5
                 213A     0411         0          0        0          5
                 214A     3441         0          0        0        224
                 215A     3441         0          0        0        225
                 216A     0410         0          0        0          9
                 217A     0449         0          0        0         49
                 218A     0449         0          0        0         51
                 219A     3452         0          0        0         12
                 220A     0452         0          0        0          4
                 221A     0452         0          0        0          6
                 222A     3431         0          0        0         33
                 223A     3431         0          0        0         38
                 224A     2430         0          0        0         14
                 225A     2430         0          0        0         14
                 226A     4430         0          0        0         15
                 227A     4430         0          0        0         15
                 228A     0430         0          0        0          4
                 229A     0430         0          0        0          4
                 230A     1430         0          0        0         11
                 231A     1430         0          0        0         23
                 232A     0456         0          0        0         96
                 233A     7433         0          0        0          9
                 234A     0333         0          0        0          3
                 235A     7641         0          0        0         10
    08/28/2007                        FedEx Ground                             COLO2
    23:16:29                        LANE FULL REPORT                  reptClaneFulls
                                                                              Page 4
                          Next               Sorters
                          Load         Main            Auto Smalls
                 Chute    Point  Primary  Secondary  Primary  Secondary
                 236A     0802         0          0        0          5
                 240A     0631         0          0        0        111
                 241A     0551         0          0        0          3
                 245A     0958         0          0        0         71
                 246A     0554         0          0        0         72
                 247A     0923         0          0        0         48
                 248A     0371         0          0        0         31
                 249A     0972         0          0        0         49
                 250A     0381         0          0        0          3
                 251A     0619         0          0        0         27
                 253A     0604         0          0        0         48
                 254A     0132         0          0        0         57
                 255A     0132         0          0        0         53
                 257A     0942         0          0        0         16
                 307A     0951         0          0        0        138
                 308A     0464         0          0        0         22
                 309A     0641         0          0        0         45
                 310A     0641         0          0        0         47
                 311A     0122         0          0        0         16
                 312A     0971         0          0        0         76
                 313A     0602         0          0        0         37
                 314A     0841         0          0        0          9
                 315A     0841         0          0        0          8
                 317A     0958         0          0        0          2
                 318A     0532         0          0        0         35
                 320A     0604         0          0        0         16
                 322A     0981         0          0        0         90
                 323A     0371         0          0        0         42
                 324A     0972         0          0        0         13
                 325A     0372         0          0        0         35
                 326A     0928         0          0        0         14
                 327A     0619         0          0        0         78
                 328A     0328         0          0        0         17
                 330A     0303         0          0        0         27
                 331A     0923         0          0        0          1
                 332A     0336         0          0        0          3
                 333A     7850         0          0        0          7
                 335A     0146         0          0        0          8
                 337A     0454         0          0        0         20
                 338A     3445         0          0        0         86
                 339A     0445         0          0        0        371
                 340A     1441         0          0        0         42
                 341A     2442         0          0        0        111
                 342A     0441         0          0        0         59
                 343A     1442         0          0        0         23
                 344A     0442         0          0        0         28
                 345A     7441         0          0        0         66
                 346A     4441         0          0        0         73
                 347A     2441         0          0        0         72
                 348A     3462         0          0        0         12
                 349A     0462         0          0        0         62
    08/28/2007                        FedEx Ground                             COLO2
    23:16:29                        LANE FULL REPORT                  reptClaneFulls
                                                                              Page 5
                          Next               Sorters
                          Load         Main            Auto Smalls
                 Chute    Point  Primary  Secondary  Primary  Secondary
                 350A     0447         0          0        0         36
                 351A     0447         0          0        0         43
                 352A     3468         0          0        0          2
                 353A     0468         0          0        0         13
                 354A     0142         0          0        0         26
                 356A     0436         0          0        0          7
                 357A     0436         0          0        0          5
                 359A     0480         0          0        0         20
                 RLBL                  0         47        0          0
                 SSBL                  0        127        0          0
                 SSGN                  0         32        0          0
                 SSRD                  0        323        0          0
                 ======================================================
                 TOTAL:                0       5071        0       6630

Maybe you are looking for

  • Michael's Weekly Ad does not load in Firefox, but it loads in Internet Explorer

    My wife and I have different computers, and she is interested in many ads for craft stores and the like. As such, she's been telling me how the Michael's Weekly Ad (http://weeklyad.michaels.com) does not load on her computer. Just for a kick, I thoug

  • An unknown error occurred (-50) while uploading my library from a disc.

    I seriously need some help here. I recently wiped my computer and reinstalled everything. I have a PC with Windows XP Pro. I made sure that I backed up my entire iTunes library on DVD-RW's. My entire Libray is on five of these. Disc one and two works

  • How to save a PDF document that I have received

    I apologize if this is the wrong group but I know there is a way to save a doc in the print menu but this is a bit different. I received a pdf doc as an attachment to an email and I need to save it. I am in the Preview window with the doc open and I

  • Mass Activity Changes

    I have a role with lots of t_code and i would like to give them full authorization, but change all ACTIVITY to 03. is there a way to change them all at once. thank you

  • FireWire 400 External Superdrive Not Working

    Hi I have an older Lacie Design by FA Porsche Superdrive connected to Mac Book Pro running OS 10.5.1 via Fire Wire 400. I am trying to burn a DVD using Toast 8 but I keep recieving Error message -50 'the connection is unstable' and the DVD won't even