This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: ASSIGNMENT 5 More Objects, Files, and an Image Viewer COMP-202A, Fall 2010, All Sections Due: Friday, December 3, 2009 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all the general instructions and regulations for assignments. Graders have the discretion to deduct up to 10% of the value of this assignment for deviations from the general instructions and regulations. Part 1, Question 1: 0 points Part 2, Question 1: 5 points Part 2, Question 2: 40 points Part 2, Question 2: 35 points Part 2, Question 2: 20 points 100 points total Part 1 (0 points): Warm-up Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the second part of the assignment, which will be graded. If you have difficulties with the questions of Part 1, then we suggest that you consult the TAs during their office hours; they can help you and work with you through the warm-up questions. Warm-up Question 1 (0 points) Write a Java program which consists of one class called ReverseFile . This class should define one method, main() , which does the following: Check whether there are exactly two command-line arguments. If the number of command-line arguments is not exactly two, your program should display the following message on the standard error stream: Usage: java ReverseFile <input-file> <output-file> It should then terminate. Attempt to open the file whose path is given by the first command-line parameter for reading. Attempt to open the file whose path is given by the second command-line parameter for writing. Read the input file line by line and reverse the characters within each line (that is, the String "abcde" should become the String "edcba" ) Write the reversed lines to the output file, but in the reverse order; that is, the first line in the input file should be the last line in the output file, the second line in the input file should be the second last line in the output file, and so on. Close the files once it has read and reversed all the lines from the input file, and written the reversed lines to the output file in the reverse order. 1 Make sure that the header of your main() method is the following: public static void main(String args) throws IOException The throws IOException clause of the method header will allow your program to compile despite the fact that opening a file for reading or for writing can result in IOException s being thrown. Hint: In order to reverse the order in which the lines appear in the output file, your program will most likely have to store them in memory. Note that your program should be able to handle a file containing any number of lines, up to the amount of memory available to the Java Virtual Machine....
View Full Document
This note was uploaded on 02/22/2011 for the course COMP 202 taught by Professor Verbrugge during the Fall '07 term at McGill.
- Fall '07