Comp 274 week 6 programming assignment

170 views
132 views

Published on

The Driving Academy Program
The purpose of this lab is to give you a chance to use some of the data stream tools we have been discussing in a simple application. The assignment is to write a driving academy application that allows a user to manipulate the records of students of a driving academy.
Your program will present a GUI interface which allows the user to specify student id, student name, and instructor name. It also allows the user to record grades for the midterm, final, and driving test. It displays the current overall average grade for the student. It provides a place for instructor comments to be entered and displayed. Finally, it provides buttons that permit student records to be added, fetched, updated, and deleted. There is also a button to reset the fields of the GUI to their initial condition, and there is a place where the status of each requested operation is displayed. The GUI for this program is displayed below.
You will be given the graphical user interface class for this assignment. Your job is to add the necessary event handling and data management classes to make this application work and meet the requirements as detailed below. You are NOT allowed to change the GUI.
Required program elements:
Only the 5 buttons generate events. No other GUI component generates any events.
You MUST use a single named inner class as the event handler class and register a single object of this class with the 5 buttons.
You must have a separate class which manages the student record data. You will have three classes in your application: the user interface class (including its event handling inner class), the student data manager class, and the student record class that is used to consolidate all information about a student. The user interface class creates ONE instance of the student data manager in its constructor and stores it in a member variable to be used in the event handler inner class. Objects of the student record class are used to pass student information between the GUI event handler and the data manager. Student record objects are also written into files and read from files by the data manager.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
170
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Comp 274 week 6 programming assignment

  1. 1. SOLUTIONJUG.COMCLICK HERE TO GET THE SOLUTION !!!!!!!!COMP/274 - Week 6 Programming AssignmentThe Driving Academy ProgramThe purpose of this lab is to give you a chance to use some of the data stream tools we have beendiscussing in a simple application. The assignment is to write a driving academy application thatallows a user to manipulate the records of students of a driving academy.Your program will present a GUI interface which allows the user to specify student id, student name,and instructor name. It also allows the user to record grades for the midterm, final, and driving test.It displays the current overall average grade for the student. It provides a place for instructorcomments to be entered and displayed. Finally, it provides buttons that permit student records to beadded, fetched, updated, and deleted. There is also a button to reset the fields of the GUI to theirinitial condition, and there is a place where the status of each requested operation is displayed. TheGUI for this program is displayed below.You will be given the graphical user interface class for this assignment. Your job is to add thenecessary event handling and data management classes to make this application work and meet therequirements as detailed below. You are NOT allowed to change the GUI.Required program elements:1. Only the 5 buttons generate events. No other GUI component generates any events.2. You MUST use a single named inner class as the event handler class and register a single object of this classwith the 5 buttons.3. You must have a separate class which manages the student record data. You will have three classes inyour application: the user interface class (including its event handling inner class), the student datamanager class, and the student record class that is used to consolidate all information about a student. Theuser interface class creates ONE instance of the student data manager in its constructor and stores it in amember variable to be used in the event handler inner class. Objects of the student record class are used topass student information between the GUI event handler and the data manager. Student record objects arealso written into files and read from files by the data manager.4. The student data manager must provide methods which support adding, fetching, updating, anddeleting student records. The parameters and return values for these methods are specified below.5. The student data manager must store a student’s record in a file whose name is the same as thestudent’s id. (ie… Student 12345 has his or her record stored in a file named 12345 in the directorywhere all student records are being kept.) All student records must be placed in some base directoryknown to the data manager.6. The student data manager must use ObjectInput/OutputStreams to read/write student recordobjects from/to files. The student data manager will NOT deal with reading or writing individual dataitems contained in the student record object. Appropriate exception handling must be used for allthese file operations.7. The student record class must contain the following data:
  2. 2. Student ID, Student Name, Instructor Name, Instructor Comments,Midterm Grade, Final Grade, Driving Grade, Overall AverageThis must be a serializable class since objects from this class are going to be stored and retrievedfrom files.8. The following summarizes the operational behavior of each button:A. Common: For all buttons except the reset button, the student id field must contain a valid positiveinteger value. You must provide exception handling which deals with the case of an invalidstudent id. If the student id is not valid, you must display an error message in the command statustext field at the bottom of the display and terminate the requested operation.B. Common: For add and update operations, you must create a student record object and store thedata from the 8 text fields into the student record object. This must be done in the event handlerbecause the event handler knows about the GUI and the student data manager does not. You mustinclude exception handling to deal with the case where one of the three grade text fields containssomething other than a numeric value. In case of this error, pop up a message dialog indicatingwhat error has occurred and do not continue building a student record. In addition, reset the userinterface to its original values as shown in the diagram above. If the three grade fields are valid, addthe three grades together, divide by 3.0, and store the result in the overall average text field andinto the student record. The data should be displayed with 2 digits after the decimal point.C. Add: When the add button is pushed, the event handler must create a student record object and ifthe object is successfully created, pass it to the data manager’s add method. The data managermust return a string indicating success or failure of the operation. The operation can fail if there issome exception that occurs when trying to write the file, OR if there is already a file for that studentid. You CAN NOT add the same student id more than one time. The result from the call to the addmethod must be displayed in the command status text field.D. Update: When the update button is pushed, the event handler must create a student record objectand if the object is successfully created, pass it to the data manager’s update method. The datamanager must return a string indicating success or failure of the operation. The operation can fail ifthere is some exception that occurs when trying to write the file, OR if there is NOT already a file forthat student id. You cannot update a student record unless a record was previously stored for thatstudent. The result from the call to the update method must be displayed in the command statustext field.E. Fetch: When the fetch button is pushed, the event handler must call the data manager’s fetchmethod, passing to it the id of the student record to be retrieved. If the file for that student id doesnot exist, the fetch method returns a null indicating that no record was found, and the event handlermust display a string to the command status text field indicating the failure. If the file exists, thedata manager will read a student record object from the file for that student id and return thatstudent record as the result. The event handler will take all the fields from the returned studentrecord and update all the fields of the GUI to reflect the data from the record. Then it will output astring indicating success to the command status text field.F. Delete: When the delete button is pushed, the event handler must call the data manager’s deletemethod, passing to it the id of the student record to be deleted. If the file for that student id doesnot exist, the delete method returns a string indicating that no record was found, and the eventhandler will output that string to the command status text field indicating the failure. If the file
  3. 3. exists, the data manager will delete the file for that student id and return a string indicating that therecord was deleted. The returned string is displayed in the command status window.G. Reset: When the reset button is pushed, the event handler will reset the user interface to the valuesshown in the diagram above.9. The data manager will need to have a base directory where it keeps all the files for the studentrecords. The constructor of the student data manager class should check to see if the directoryexists and create it if it doesn’t already exist. There is info at the end of the lecture that shows howdo deal with this.10. Just a warning about file names… when you are building a file name in a string that the datamanager will use, make sure that you use double backslashes. For instance, lets say that basedirectory for student records is c:StudentRecords. You would have a variable something like this:String baseDir = “c:StudentRecords”;Then to make a string for student number 1234, you would do this:String fileName = baseDir + 1234;Notice that the double backslashes appear between the directory name and the student id part ofthe filename.Here is the code to the user interface for this program.import java.awt.*;import java.awt.event.*;import javax.swing.*;public class UserInterface extends JFrame{private StudentDataManager dataManager = new StudentDataManager();private JButton add, fetch, update, delete, reset;private JLabel sidl, namel, instl;private JTextField sidtf, nametf, insttf;private JLabel commentl;private JTextArea commentta;private JScrollPane commentsp;private JLabel midterml, finall, drivingl, overalll;private JTextField midtermtf, finaltf, drivingtf, overalltf;private JLabel statusl;private JTextField statustf;public UserInterface(){
  4. 4. super(“Rick’s Driving Academy”);buildTop();buildBottom();buildRight();buildLeft();pack();setDefaultCloseOperation(EXIT_ON_CLOSE);setVisible(true);}private void buildTop(){Dimension dim = new Dimension(60,25);JPanel tp = new JPanel();sidl = new JLabel(“Student ID”);namel = new JLabel(“St. Name”);instl = new JLabel(“Instructor”);sidtf = new JTextField(8);nametf = new JTextField(8);insttf = new JTextField(8);sidl.setPreferredSize(dim);namel.setPreferredSize(dim);instl.setPreferredSize(dim);sidl.setHorizontalAlignment(SwingConstants.RIGHT);namel.setHorizontalAlignment(SwingConstants.RIGHT);instl.setHorizontalAlignment(SwingConstants.RIGHT);tp.add(sidl);tp.add(sidtf);tp.add(namel);tp.add(nametf);tp.add(instl);tp.add(insttf);add(tp, BorderLayout.NORTH);}private void buildBottom(){Dimension dim = new Dimension(90,25);JPanel bp1 = new JPanel();add = new JButton(“Add”);fetch = new JButton(“Fetch”);update = new JButton(“Update”);
  5. 5. delete = new JButton(“Delete”);reset = new JButton(“Reset”);add.setPreferredSize(dim);fetch.setPreferredSize(dim);update.setPreferredSize(dim);delete.setPreferredSize(dim);reset.setPreferredSize(dim);bp1.add(add);bp1.add(fetch);bp1.add(update);bp1.add(delete);bp1.add(reset);JPanel bp2 = new JPanel();statusl = new JLabel(“Command Status:”);statustf = new JTextField(32);statustf.setEditable(false);bp2.add(statusl);bp2.add(statustf);JPanel bp3 = new JPanel(new GridLayout(2,1));bp3.add(bp1);bp3.add(bp2);add(bp3, BorderLayout.SOUTH);}private void buildRight(){JPanel rp = new JPanel();rp.setLayout(new BorderLayout());rp.setBorder(BorderFactory.createEmptyBorder(0,10,0,10));commentl = new JLabel(“Instructor Comments”);commentl.setHorizontalAlignment(SwingConstants.CENTER);rp.add(commentl, BorderLayout.NORTH);commentta = new JTextArea(6,30);commentsp = new JScrollPane(commentta);rp.add(commentsp, BorderLayout.CENTER);add(rp, BorderLayout.CENTER);}private void buildLeft(){JPanel lp = new JPanel();lp.setLayout(new GridLayout(4,2,5,5));lp.setBorder(BorderFactory.createEmptyBorder(0,10,0,0));
  6. 6. midterml = new JLabel(“Midterm”);finall = new JLabel(“Final”);drivingl = new JLabel(“Driving”);overalll = new JLabel(“Overall”);midtermtf = new JTextField(“0″,3);finaltf = new JTextField(“0″,3);drivingtf = new JTextField(“0″,3);overalltf = new JTextField(“0″,3);overalltf.setEditable(false);lp.add(midterml);lp.add(midtermtf);lp.add(finall);lp.add(finaltf);lp.add(drivingl);lp.add(drivingtf);lp.add(overalll);lp.add(overalltf);add(lp, BorderLayout.WEST);}public static void main(String[] args){UserInterface myApp = new UserInterface();}}Take screen shots of the output of your program. Paste the screen shots and yoursource code for your programs into a Word document. Submit your Word document.Screenshot 1Screenshot 2Screenshot 3Screenshot 4CLICK HERE TO GET THE SOLUTION !!!!!!!!

×