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

Here is the question i posted yesterday, the problem is i can\'t create the file

ID: 3628432 • Letter: H

Question

Here is the question i posted yesterday, the problem is i can't create the file and have it read in. It says file is not found? Can someone help me?? thanks to whoever helped me this far, if someone could just help me with creating and reading in the file so that it runs correctly, that would be great.
Java Simple Word Processor

Question Details

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

RE: Java Simple Word Processor


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);
}
}
}



Explanation / Answer

please rate - thanks

make sure the .txt file is in the correct directory.

make sure the case is all okay.

look at the file in the directory and be sure it's name is correct and not ending in .txt.txt

you should see the name without the .txt, but a txt file icon

try changing the code and the file name to something short and see if it works.

I actually debugged it with a file named input.txt --- will have to change this line of code

try{ Scanner finput=new Scanner(new File("State_Of_The_Union_2011_Address.txt"));

to this

try{ Scanner finput=new Scanner(new File("input.txt"));