You are on page 1of 2

Spring 2012 CS 302 Object Oriented Design Lab Midterm Exam Date: March 5, 2012 Name: ______________________________ Notes:

You are required to upload your implementations to Blackboard. This is due by 12:00 PM today. Please note that you can upload your submission only once, so make sure you are uploading the final version to Blackboard. Write down your name and hand in this sheet to TA at the end of lab. Search Students Records The application provides a convenient user interface for searching students records. Search results can also be saved to a file on demand. Students records are laid out in file students.txt; one record per line. Each record consists of three fields: student name, student number, and major. Two consecutive fields are separated by a tab (i.e., \t). User may apply a search filter on any of these fields. However, at most one filter can be applied at once. For example: a search filter can be on students name or major but not on both at the same time. Search filters are substring filters. That means if any record contains the search text as a substring then it will be considered as a match and consequently will be included in the search result. Because an empty string is a substring of every string, an empty filter retrieves all records from file. Search result is displayed in sorted order based on student name. If two or more students have the same name, then these records are subsequently sorted based on student number, which is unique. Retrieved records can be saved to a user specified file in the same sorted order as they are displayed. The GUI should look as shown below. A user picks up a search field from the combo box next to Search Field label. Search text is entered in the text field next to Search Text label. The search result is displayed in text area located at the center of the GUI. This text area is not user editable. If Save button is clicked, search result will be saved to a file as named in the text field next to File Name label. As opposed to search text, a valid file name is always non-empty. Skeletal code is provided. You have to modify it to accomplish the following goals: 1. (25 points) Use grid layout managers in order to organize GUI components on the frame. Consider the diagrams below strictly as references. 2. (25 points) Read records from file students.txt. Handle all exceptions regarding file IO. Write corresponding error messages to System.err. Hint: Use Scanner; to instantiate scanner use this constructor: Scanner(File source). Use StringTokenizer to extract fields from a line of input. 3. (10 points) In addition to IO exceptions, report to System.err, if you encounter any malformed record while reading records from file. A malformed record is one that has fewer than three fields in it. Your program should just report such malformed records, ignore those errors, and skip to the next record in the file.

Page 1 of 2

Spring 2012 CS 302 Object Oriented Design Lab Midterm Exam Date: March 5, 2012
4. (20 points) Sort students records before displaying them as search result. Tweak StudentRecord class such that you are able to use GenericSort.sort() to sort selected records. 5. (20 points) The required functionality for saving search result is provided. Add event handler to Save button such that the goal of saving search result to a file is achieved on click. Hint: you may create a new class SaveEventListener similar to the existing class SearchEventListener. You may assume that no search will encounter more than 128 records.

Page 2 of 2

You might also like