03-Week.docx

advertisement
Week 03 assignment
We will start with the example code used in class Thursday.
You are to write a program that uses Chooser to find a file, reads it (assuming that it is an ASCII text file),
and should print out (using System.out.println):
1. The number of lines of the file. Lines are defined by BufferedReader.
hint: Start with an int variable initialized to 0. Increment it every time you successfully read a
line.
2. The longest line in the file. Determine this by using the .length() method of String.
hint: have a String variable contain the currently longest line. When you read a line, if it is
longer than the currently longest line, replace the currently longest line with the line you just
read.
3. The length of the longest line in the file.
4. The shortest line (that isn’t empty) in the file.
hint: this is tricky. You will need to do checking within an if statement block that makes sure
the line has a length greater than zero. You may need to use a Boolean or separate read to
make sure to start the “currently shortest line” with a line from the file.
5. The length of the shortest line (that isn’t empty) in the file.
6. The total number of characters in the file (excluding cr/lf line terminators). That is, just sum up
the lengths of each line.
Notes:





Your program should be in a file named “FileCheck.java” and the class name should (of course)
be “FileCheck”.
Your name should be in a comment in the first line of your program
Your program should print your name as its first line of output.
All output should be clear and understandable’
The program should contain appropriate comments.
Download