SlideShare une entreprise Scribd logo
1  sur  6
SOLUTIONJUG.COM
CLICK HERE TO GET THE SOLUTION !!!!!!!!
COMP/274 - Week 6 Programming Assignment
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.
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.
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();
}
}
Take screen shots of the output of your program. Paste the screen shots and your
source code for your programs into a Word document. Submit your Word document.
Screenshot 1
Screenshot 2
Screenshot 3
Screenshot 4
CLICK HERE TO GET THE SOLUTION !!!!!!!!

Contenu connexe

En vedette

Funcionamiento del vehículo, servicio y mantenimiento
Funcionamiento del vehículo, servicio y mantenimientoFuncionamiento del vehículo, servicio y mantenimiento
Funcionamiento del vehículo, servicio y mantenimientoVictor Ruiz Ortiz
 
Proyecto de mantenimiento industrial, norma Covenin
Proyecto de mantenimiento industrial, norma CoveninProyecto de mantenimiento industrial, norma Covenin
Proyecto de mantenimiento industrial, norma CoveninDiego Castañeda
 
Mantenimiento de maquinas industriales
Mantenimiento de maquinas industrialesMantenimiento de maquinas industriales
Mantenimiento de maquinas industrialesverocha66
 

En vedette (6)

Funcionamiento del vehículo, servicio y mantenimiento
Funcionamiento del vehículo, servicio y mantenimientoFuncionamiento del vehículo, servicio y mantenimiento
Funcionamiento del vehículo, servicio y mantenimiento
 
Proyecto De Mantenimiento
Proyecto De MantenimientoProyecto De Mantenimiento
Proyecto De Mantenimiento
 
Proyecto de mantenimiento industrial, norma Covenin
Proyecto de mantenimiento industrial, norma CoveninProyecto de mantenimiento industrial, norma Covenin
Proyecto de mantenimiento industrial, norma Covenin
 
Empresa de aseo, limpieza y desinfeccion
Empresa de aseo, limpieza y desinfeccionEmpresa de aseo, limpieza y desinfeccion
Empresa de aseo, limpieza y desinfeccion
 
Mantenimiento de maquinas industriales
Mantenimiento de maquinas industrialesMantenimiento de maquinas industriales
Mantenimiento de maquinas industriales
 
Mantenimiento motor diesel
Mantenimiento motor dieselMantenimiento motor diesel
Mantenimiento motor diesel
 

Dernier

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 

Dernier (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 

Comp 274 week 6 programming assignment

  • 1. SOLUTIONJUG.COM CLICK HERE TO GET THE SOLUTION !!!!!!!! COMP/274 - Week 6 Programming Assignment 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. 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:
  • 2. 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
  • 3. 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. 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() {
  • 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. 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. 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 your source code for your programs into a Word document. Submit your Word document. Screenshot 1 Screenshot 2 Screenshot 3 Screenshot 4 CLICK HERE TO GET THE SOLUTION !!!!!!!!