CS 302 File I/O Exercises: Lectures 10 and 21 Directions: - You may work in groups of no more than three. - Turn in a copy of the final product (with your name on it) +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Exercise 1 Given: the Furniture class definition seen previously. Task: parse a file named input1.txt, which contains data for a number of Furniture items. Create an array of instances of the Furniture class, and print all of the names and IDs at the end of your program (print these in any format you wish). The input1.txt file has the following format: ;;;; ;; ;;;; ;; ... where ID is an integer, all inputs on line 2 are doubles (and correspond to the Fields in the furniture class, in the specified order), and all inputs on line 3 are booleans. Example file: ---------------------------------- 1 10;13.0;50;70;200 true;false;false 3 1;0.5;2.0;2.0;10 true;true;false ---------------------------------- Additional Specifications: You may assume that the last line in the file will have the last line of input for some furniture object, and every furniture object will have the three corresponding lines described (in particular, the # of lines in the file is a multiple of 3.. Assume that the ID is *always* in proper format (i.e., a single integer and no other junk on that line). However, the other two lines may have formatting errors (which you'll handle via exceptions). If a formatting error occurs, skip to the next Furniture item (this may involve skipping one or two lines). Do not create a furniture object if a formatting error is detected. Use exception handling where it's required, and you must use try-catch blocks (rather than simply include a "throws" clause in the method signature). +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Exercise 2 (challenge) Given: the Furniture and Clothing class definitions seen previously. Task: parse a file named input2.txt, which may contain data for furniture and clothing items mixed together. Create an array of SaleItems (as defined previously) and fill it with the objects read in from the file. Print all of the names and IDs of the SaleItems at the end of your program (print these in any format you wish). File Format: The Furniture items in the file are formatted as described in Exercise 1. The Clothing items are in the following format (each Clothing item has 4 lines). where ID is an integer, and the remaining three values correspond to the fields in furniture (in the specified order). Example file: ---------------------------------- 1 10;13.0;50;70;200 true;false;false 22 13.50 7 true 3 1;0.5;2.0;2.0;10 true;true;false ---------------------------------- Additional Specifications: All assumptions from Exercise 1 hold here. Similarly, you may assume that the last line in the file will have the last line of input for some furniture or clothing object, and every clothing object will have the four corresponding lines described. Assume that the ID is *always* in proper format (i.e., a single integer and no other junk on that line). However, the other two lines may have formatting errors (which you'll handle via exceptions). If a formatting error occurs, skip to the next SaleItem (this will involve figuring out how many lines to skip). Do not create a SaleItem (furniture or clothing object) if a formatting error is detected. Use exception handling where it's required, and you must use try-catch blocks (rather than simply include a "throws" clause in the method signature). Good luck!