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

i\'m new to programming in this language and i have no ideawhat im doing. i comp

ID: 3613460 • Letter: I

Question

i'm new to programming in this language and i have no ideawhat im doing. i completed c programming but my class onlyspent 2 days on c++ so i dont know alot of those techniques used.so i have this: Write a program that reads a textfile and outputs thefollowing statistics: the average line length, the longest twolines, the average word length, and the longest word. A wordis defined as a maximal sequence of consecutive characters that arenot white spaces. The static function booleanCharacter.isWhitespace(char) returns true if the input character isa white space. The program, invoked as java fileStatistics<filename>, returns the required statistics with appropriatemessages for the user. i have no idea where to even start. we are using javaprogram eclipse for this project if that matters. if someone couldplease help i would really appreciate it thank you. i'm new to programming in this language and i have no ideawhat im doing. i completed c programming but my class onlyspent 2 days on c++ so i dont know alot of those techniques used.so i have this: Write a program that reads a textfile and outputs thefollowing statistics: the average line length, the longest twolines, the average word length, and the longest word. A wordis defined as a maximal sequence of consecutive characters that arenot white spaces. The static function booleanCharacter.isWhitespace(char) returns true if the input character isa white space. The program, invoked as java fileStatistics<filename>, returns the required statistics with appropriatemessages for the user. i have no idea where to even start. we are using javaprogram eclipse for this project if that matters. if someone couldplease help i would really appreciate it thank you.

Explanation / Answer

please rate - thanks import java.util.*; import java.io.*; public class wordcount{ public static void main(String[] args)throwsFileNotFoundException {String filename,input,longestw="",word=""; inttotalcharacters=0,lines=0,longest1=0,longest2=0,words=0,charlongestw=0,totalwordcharacters=0; int i,j,n,prev,length,spaces=0; char ch; Scanner in=new Scanner(System.in); filename=args[0]; try{ Scanner finput=new Scanner(new File(filename)); if(!finput.hasNext())       {System.out.println(filename+"empty-program aborting");       System.exit(1);        }       while(finput.hasNextLine())          {lines++;                           input=finput.nextLine();              n=input.length();              totalcharacters+=n;               if(n>longest2)                  {if(n>longest1)                       {longest2=longest1;                       longest1=n;                       }                   else                       longest2=n;                   }              prev=0;              word="";                    for(i=0;icharlongestw)                              {charlongestw=length;                                longestw=word;                                 }                             word="";                              }                       else                           word+=ch;                       System.out.println("word="+word);                      }                                   } System.out.println("FILE STATISTICS"); System.out.println("average characters per line:"+(double)totalcharacters/lines); System.out.println("characters in longest line:"+longest1); System.out.println("characters in second longest line:"+longest2); System.out.println("average word length:"+(double)(totalwordcharacters)/words); System.out.println("longest word: "+longestw); finput.close(); System.exit(0); }catch ( FileNotFoundException e) {System.out.println("The file you entered either do notexist or the name is spelled wrong."); System.exit(2); } } }