Write a program that counts the number of words in President

Write a program that counts the number of words in President Abraham Lincoln’s Gettysburg address (see below). Create a text file called Lincoln.txt with the following text Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth. Files to be submitted • WordCount.java • Lincoln.txt

Create a table named Student with the following details: Column Data Type Length Condition Values StudentID Int Not null (primary key) Name Varchar 25 Not null Major Text 4 Not null Level Varchar 10 -- Freshman, Sophomore, Junior, Senior GPA Decimal 2,2 2) Insert Sample Data 3) Write a program that accepts student id as input and displays student details. If the student doesn’t exist, display message. Files to be submitted • Student.sql • DisplayStudent.java

Solution

Please follow the code and comments for description :

CODE :

WordCount.java :

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class WordCount {

    public static void main(String[] args) throws FileNotFoundException {
        File inputFile = new File(\"Lincoln.txt\"); // file objects
        BufferedReader in = (new BufferedReader(new FileReader(inputFile))); // reader and the writer class objects
        try {
            System.out.println(\"Reading Data From the Input File...\"); // message
            String currentLine; // local variables
            int wc = 0;
            String words[];
            while ((currentLine = in.readLine()) != null) { // read the data line by line
                words = currentLine.split(\"\\\\s\");
                wc = wc + words.length;
            }
            System.out.println(\"The total Words in the File are : \" + wc); // message
        } catch (IOException e) { // catch the exceptions any
            e.printStackTrace();
        } finally {
            try {
                if (in != null) {
                    in.close(); // close the input file
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}


Lincoln.txt :

Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate -- we can not consecrate -- we can not hallow -- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -- that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -- that we here highly resolve that these dead shall not have died in vain -- that this nation, under God, shall have a new birth of freedom -- and that government of the people, by the people, for the people, shall not perish from the earth.


OUTPUT :

Reading Data From the Input File...
The total Words in the File are : 277


Hope this is helpful.

Write a program that counts the number of words in President Abraham Lincoln’s Gettysburg address (see below). Create a text file called Lincoln.txt with the fo
Write a program that counts the number of words in President Abraham Lincoln’s Gettysburg address (see below). Create a text file called Lincoln.txt with the fo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site