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

Speed Reader (Adapted from ht tp://nifty.stanford.edu/2015/posera-speed -reader/

ID: 3808732 • Letter: S

Question

Speed Reader (Adapted from ht tp://nifty.stanford.edu/2015/posera-speed -reader/) 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 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

NOTE : All the deliverables are completed. And moreover, used Java language because the question was not language specific


import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
*
* @author zubair
*/
public class SpeedReader {
  
        private int outputSpeed;
        private String inputString;
      
        public void getInput() {
            /*
             * Create a window to get the inputs from the users
             */
            JTextField inputString = new JTextField();
            JTextField outputSpeed = new JTextField();
            Object[] message = {
                "Input String :", inputString,
                "Ouput Speed (words/min) :", outputSpeed
            };

            int option = JOptionPane.showConfirmDialog(null, message, "OK", JOptionPane.OK_CANCEL_OPTION);
          
            if (option == JOptionPane.OK_OPTION) {
                this.inputString = inputString.getText().trim();
                this.outputSpeed = Integer.valueOf(outputSpeed.getText());
            }
        }
      
        public void outputString() throws InterruptedException {
            /*
             * Get delay per word in milliseconds
             */
            double timeDelayPerWord = 60* 1000 / outputSpeed;          
            String[] splittedWords = inputString.split(" ");
          
            /*
             * New window to display output, in addition to command line
             */
            JFrame jFrame = new JFrame();
            JTextArea jTextArea = new JTextArea();
            jFrame.add(jTextArea);
            jFrame.setVisible(true);
            jFrame.setSize(600, 600);
            jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
            /*
             * Ouput the words with delay to both window and commandline
            */
            for (String word : splittedWords) {
                System.out.print(word.trim() +" ");
                jTextArea.append(word.trim() +" ");
                Thread.sleep((long) timeDelayPerWord);
            }
            System.out.println();

        }

        public static void main(String args[]) throws InterruptedException {
            SpeedReader speedReader = new SpeedReader();
            speedReader.getInput();
            speedReader.outputString();
        }
}

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