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

I have to create a simple word processor in a program called: SimpleDataProcesso

ID: 3628420 • Letter: I

Question

I have to create a simple word processor in a program called: SimpleDataProcessor.java to perform the following functions:

1-It opens a text file of the President's State of the Union speech from earlier in the year. Call the file State_Of_The_Union_2011_Address.txt

2-It provides word statistics for the file and displays the total number of words plus total number of characters (spaces included), the total number of the following prepositions (at, about, in, of until) and the total number of occurrencces of the definite article "the" or "The".

3-It creates a new file called: modified_State_Of_The_Union_2011_Address.txt. It replaces the occurences of the definite article "The" with "A" and "the" with "a"-case sensitive(the umber of replacements must match the number of occurences of "the" and "The".

4-It must consist of the following items:
UML Diagram + OOP Structure: Data Fields and Methods
Source code + correct program functionality
OOP Style + Source Code Documentation

Explanation / Answer

please rate - thanks

assumed only whitespaces separating words

import java.util.*;
import java.io.*;
public class wordcount{
public static void main(String[] args)throws FileNotFoundException
{String input,word="";
int totalcharacters=0,words=0,charlongestw=0,totalwordcharacters=0;
int i,j,n,prev,length,spaces=0,prep=0,the=0;
char ch;
PrintStream output=new PrintStream(new File("modified_State_Of_The_Union_2011_Address.txt"));
try{ Scanner finput=new Scanner(new File("State_Of_The_Union_2011_Address.txt"));
if(!finput.hasNext())
      {System.out.println("file empty-program aborting");
      System.exit(1);
       }
      while(finput.hasNextLine())
          {   
            input=finput.nextLine();
            n=input.length();
                        prev=0;
            word="";       
            for(i=0;i<=n;i++)
                {if(i!=n)
                      ch=input.charAt(i);
                    else
                       ch=' ';
                    if(Character.isWhitespace(ch))
                         {words++;
                            spaces++;                           
                            length=i-prev;
                            prev=i+1;
                            totalwordcharacters+=length;
                            if(word.compareToIgnoreCase("at")==0||
                                word.compareToIgnoreCase("about")==0||
                                word.compareToIgnoreCase("in")==0||
                                word.compareToIgnoreCase("of")==0||
                                word.compareToIgnoreCase("until")==0)
                                      prep++;
                            if(word.compareTo("the")==0)
                                  {the++;
                                    word="a";
                                    }
                            else if(word.compareTo("The")==0)
                                  {the++;
                                    word="A";
                                    }

                           
                            output.print(word+" ");
                            word="";
                                }
                        else
                            word+=ch;
                         }
    output.println();                    
          }
System.out.println("FILE STATISTICS");
System.out.println("total number of words: "+(words-1));
System.out.println("total number of prepositions: "+prep);
System.out.println("total number of the or The: "+the);
System.out.println("total number of characters (spaces included): "+(totalwordcharacters+spaces));
output.close();
finput.close();
System.exit(0);
}catch ( FileNotFoundException e)
{System.out.println("The file you entered either do not exist or the name is spelled wrong.");
System.exit(2);
}
}
}