Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Speed Reader (Adapted from) This project requires you to create a program that t

ID: 3804305 • Letter: S

Question

Speed Reader (Adapted from) This project requires you to create a program that takes two inputs: A string of any length. A number of words per minute. Your program will take the string, break it up into individual words, and display it one word at a time at the desired rate. For instance, "Hello World!" at 500 words per minute would display "Hello" for 3/25^ths of a second and then "World!" for 3/25^ths of a second. You'll be surprised to discover that you can read words that are displayed quite quickly! This project has the following deliverable levels: C: Your project prints words to the command line at the desired rate. While it is printing words, those words are the ONLY thing in the command line. B: Your project prints words to another window besides the command line. A: Your project has a graphical interface that will let a user input a string, select a rate, and press a button to display the words of that string at the desired rate.

Explanation / Answer

This is platform independent code, works well in most terminals. Most part of the code is auto generated NetBeans code for GUI. The vital part is copied and commented below the main code

<CODE>

import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author Sam
*/
public class SpeedReader extends javax.swing.JFrame {

    /**
     * Creates new form SpeedReader
     */
    public SpeedReader() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                        
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("String");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jLabel2.setText("Rate");

        jTextField1.setText("1");

        jLabel3.setText("Hz");

        jButton1.setText("Start!");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(73, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jButton1))
                .addContainerGap((char)27, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                      

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
        String string = jTextArea1.getText();
        double delay = 1000/Double.parseDouble(jTextField1.getText());
        for (String s :string.split("[ \.\?!]")){
        System.out.print(ESC + "[2J");
       System.out.flush();
        System.out.print(ESC + "[1;1H");
        System.out.flush();

        System.out.println(s);
        System.out.flush();

            try {
                Thread.sleep((long)delay);
            } catch (InterruptedException ex) {
                Logger.getLogger(SpeedReader.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }                                      

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SpeedReader.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SpeedReader.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SpeedReader.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SpeedReader.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SpeedReader().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                   
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    public static final char ESC = 27;
    // End of variables declaration                 
}

<COMENTS>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { //Function is called when button is pressed

        String string = jTextArea1.getText(); //text from the text area
        double delay = 1000/Double.parseDouble(jTextField1.getText()); // calculate the delay and store it
        for (String s :string.split("[ \.\?!]")){ //split the sentence into words and for each word do the same
         for (String s :string.split("[ \.\?!]")){
        System.out.print(ESC + "[2J"); //clears the screen
       System.out.flush();
        System.out.print(ESC + "[1;1H"); //position the cursor at row1 col1
        System.out.flush();

        System.out.println(s); //print the word
        System.out.flush();

            try {
                Thread.sleep((long)delay); //Sleep or delay for desired time
            } catch (InterruptedException ex) {
                /*Logger.getLogger(SpeedReader.class.getName()).log(Level.SEVERE, null, ex);*/ //ignore pls :D
            }
        }
    }                                      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote