Driving academy application that allows a user to manipulate


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:

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 class with the 5 buttons.
3. 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.

NOTE: This is a VERY common way that real applications are structured. The user interface is designed separately from the data management aspect of the application. In our program, we have the GUI class that presents the user interface. We have the data manager class which understands what needs to be done to add, update, fetch, and delete student records using objects and files. And we have the event handler class as an inner class that can access the GUI components AND make method calls to the data manager object. Nothing in the GUI class has any knowledge of what the data manager is doing internally. Nothing in the data manage has any knowledge of what is going on in the GUI. 

4. The student data manager must provide methods which support adding, fetching, updating, and deleting 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 the student's id. (ie... Student 12345 has his or her record stored in a file named 12345 in the directory where all student records are being kept.) All student records must be placed in some base directory known to the data manager.
6. The student data manager must use ObjectInput/OutputStreams to read/write student record objects from/to files. The student data manager will NOT deal with reading or writing individual data items contained in the student record object. Appropriate exception handling must be used for all these file operations.
7. The student record class must contain the following data:
Student ID, Student Name, Instructor Name, Instructor Comments,
Midterm Grade, Final Grade, Driving Grade, Overall Average
This must be a serializable class since objects from this class are going to be stored and retrieved from 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 positive integer value. You must provide exception handling which deals with the case of an invalid student id. If the student id is not valid, you must display an error message in the command status text 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 the data from the 8 text fields into the student record object. This must be done in the event handler because the event handler knows about the GUI and the student data manager does not. You must include exception handling to deal with the case where one of the three grade text fields contains something other than a numeric value. In case of this error, pop up a message dialog indicating what error has occurred and do not continue building a student record. In addition, reset the user interface to its original values as shown in the diagram above. If the three grade fields are valid, add the three grades together, divide by 3.0, and store the result in the overall average text field and into 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 if the object is successfully created, pass it to the data manager's add method. The data manager must return a string indicating success or failure of the operation. The operation can fail if there is some exception that occurs when trying to write the file, OR if there is already a file for that student id. You CAN NOT add the same student id more than one time. The result from the call to the add method 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 object and if the object is successfully created, pass it to the data manager's update method. The data manager must return a string indicating success or failure of the operation. The operation can fail if there is some exception that occurs when trying to write the file, OR if there is NOT already a file for that student id. You cannot update a student record unless a record was previously stored for that student. The result from the call to the update method must be displayed in the command status text field.
e. Fetch: When the fetch button is pushed, the event handler must call the data manager's fetch method, passing to it the id of the student record to be retrieved. If the file for that student id does not exist, the fetch method returns a null indicating that no record was found, and the event handler must display a string to the command status text field indicating the failure. If the file exists, the data manager will read a student record object from the file for that student id and return that student record as the result. The event handler will take all the fields from the returned student record and update all the fields of the GUI to reflect the data from the record. Then it will output a string 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 delete method, passing to it the id of the student record to be deleted. If the file for that student id does not exist, the delete method returns a string indicating that no record was found, and the event handler will output that string to the command status text field indicating the failure. If the file exists, the data manager will delete the file for that student id and return a string indicating that the record was deleted. The returned string is displayed in the command status window. NOTE: To delete the file, just call the delete( ) method on the file object for the file you want to delete.
g. Reset: When the reset button is pushed, the event handler will reset the user interface to the values shown in the diagram above.
9. The data manager will need to have a base directory where it keeps all the files for the student records. The constructor of the student data manager class should check to see if the directory exists and create it if it doesn't already exist. There is info at the end of the lecture that shows how do deal with this.
10. Just a warning about file names... when you are building a file name in a string that the data manager will use, make sure that you use double backslashes. For instance, lets say that base directory 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 of the 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()
{
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");
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));
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();
}

Request for Solution File

Ask an Expert for Answer!!
Management Information Sys: Driving academy application that allows a user to manipulate
Reference No:- TGS092045

Expected delivery within 24 Hours