COP2551_43 Program 5 Summer 2004 Name_____________________ Program 5 reads two data files, one with data for the faculty member of a class and one with data for students. Data is displayed for faculty and students. The goals are to gain experience: 1. 2. 3. 4. 5. 6. 6. using command line arguments including displaying an error message if the user fails to correctly enter the arguments. reading data files including checking if the files exist and displaying appropriate messages to alert the user of a possible problem. using an abstract Parent class and implementing an abstract method that is in the abstract Parent class. accessing an instance variable in a parent class. formatting screen output. reading files and passing file names and file references as parameters to methods. using javadoc to produce html documentation files that may be viewed with a browser. For this to work as I will demonstrate in class, you must use the /** form of a comment opening to describe the class and also to describe each method. See the bottom of page 32 in your text, the class demo, and text's website for more information on javadoc. You are to implement the following classes using the specified arguments: A ClassInfo driver class that will instantiate objects from other classes as needed from within a main() method (the other classes will also instantiate objects as needed). The call to this class will be java ClassInfo faculty.data student.data where faculty.data and student.data are command line arguments specifying the data files to be processed. Verification of the command line arguments and the existence and readability of the data files will be accomplished within main(). Then Faculty and Student objects will be instantiated and they will complete the rest of the tasks except for displaying the results. The appropriate BufferedReader objects are to be instantiated in main() and passed to the Faculty and Student constructors. The only println() methods should be for Exceptions (in catch clauses) and two println() methods in main() which will be: System.out.println(faculty); System.out.println(studAry); where faculty and student are reference variables for the instantiated Professor and Student objects. Extra credit will be given if you write this entire program using no throws clauses on method headers (all Exceptions are caught). The program is to implement the following classes and methods. An abstract parent class Person with the following data fields, constructor and methods: Data Fields: A Name instance variable to reference a Name object. A String field that references an email address. Note that these fields must use the protected visibility modifier. Constructor: Person(), a constructor that takes a BuffferedReader object as an argument and initializes the Name instance variable by instantiating a Name object, passing the BufferedReader reference to the Name constructor. Then initializes the email instance variable by using the BufferedReader reference to the email string. Methods: One public abstract method with the following signature: public abstract String toString(); The above method will insure that any classes that inherit from the Person class must implement a toString() method. A Faculty class that extends Person and has the following instance variables, constructor, and methods: Instance Variables: Separate private String fields to hold a title, room number, area code and phone number. Constructor: Faculty(), that takes a BufferedReader reference for the faculty.data file(input on the command line) as a parameter. The constructor invokes super, passing the BufferedReader reference to the Person constructor, then invokes a readData() method, passing the BufferedReader reference to it. Methods: The readData() method mentioned above will use the BufferedReader reference to read and assign values to the Faculty instance variables. A toString() method that will format the output string to be displayed when a Faculty object is printed. A Student class that extends Person and has the following instance variable, constructor, and methods: Instance Variables: A reference variable for a Grades object. Constructor: Methods: Student(), that takes as an argument the BufferedReader object passed from main(). The constructor invokes super and passes the BufferedReader to the Person constructor. The Student constructor then instantiates a Grades object, passing the BufferedReader to it and assigns the Grades reference to the Grades instance variable. A toString() method that will format the output string that will be displayed when a Student object is printed. A Name class that has the following instance variables, constructor, and methods: Instance Variables: Three private String instance variables to hold the first name, last name and middle initial. Constructor: Name(), that is invoked from the Faculty or the Student classes (by instantiating Name objects) and takes as a parameter the BufferedReader reference. The constructor invokes a readName() method, passing the BufferedReader reference. Methods: The readName()that uses a StringTokenizer object and its nextToken() method to parse the name and store it in the Name class instance variables and a toString() method that will format the output string that will be displayed when a Name object is printed. A Grades class that has the following instance variables, constructor, and methods: Instance Variables: Three integer arrays to hold the quiz grades, program grades and exam grades. Float variables to hold the quiz average, program average, midterm exam average, the final exam grade, and the course average. Constructor: Grades() that is called from the Student class and takes as a parameter the BufferedReader object passed from the Student class. The constructor passes the BufferedReader reference when it invokes quizGrades(), programGrades(), examGrades() and computeAverages() methods. that read in the grades and compute the averages. The computeAverages() method must access the grade arrays in order to compute the averages. Do not compute the averages while you are reading in the grades in the other methods. A toString() method that will format the output string that will be displayed when a Grades object is printed. Methods: The quizGrades(), programGrades(), examGrades() and computeAverages() methods read in the grades and compute the averages. The computeAverages() method must access the grade arrays in order to compute the averages. Do not compute the averages while you are reading in the grades in the other methods (you will lose points if you do). For 5 Points Extra Credit: Write to a text file named data.out the same data you display on the screen. If I "cat" this file, I should see the same output I see when I execute your program. For 5 Points Extra Credit: Use not throws clauses on method headers, rather use try and catch clauses to handle all exceptions. Display useful debugging messages in your catch statements. For 5 Points Extra Credit: Add additional students to the student.data file. Modify your display so it does not scroll any students off the screen until the user allows the next student's data to be displayed. You will need to modify your code to store the students in an array. I created another class called StudAry to help me accomplish this. The turnin code will be higbee.cop2551_43.p5 . After you place your .java files and your data files in the directory you will shar, get in that directory and do the following: javadoc *.java This will produce java documentation (.html files). Then shar the directory and you will be turning in your javadoc files along with the program files. In addition, you are to turn in a folder with the following: 1. 2. 3. 4. 5. 6. A title page with your name and a brief description of your program. Your name should also be on the front of the folder and on each separate file you turn in. Printouts of the code for each of your classes. A UML class diagram for each class that shows the inheritance relationship (see Page 386, fig. 7.1 and Page 409, fig. 7.8). A brief discussion of how you tested your program. A statement letting me know if you did any of the extra credit. A brief discussion of the degree to which you succeeded (or had difficulty succeeding) in accomplishing the objectives of the assignment. I will allocate 10% of your project grade to this discussion. If you identify all problems and discuss potential solutions, you will receive all ten points. If I find problems that are not identified, less points will be awarded. Your project is due on Tuesday, July 20th at start of class. Late turnins will not be accepted, but you may turn in whatever you have for part credit provided your program compiles. Paul Higbee