In: Computer Science
You are a software development employee at a startup company. Your HR department has tasked the IT department with developing a simple application (Windows Form Application) to load and display employee records.
Your application will need to do the following:
Create an Employee Class with the following properties:
First Name
Last Name
Street Address
City
State
Zip
Create a sub class for Managers which inherits from the Employee Class. The Manager class will have the following additional properties:
Cost Center
Supervisor
Create a sub class for Developers which inherits from the Employee Class. The Developer class will have the following additional properties:
Developer Type (Script, .NET, Mobile, etc.)
Supervisor
Tax Type (W2, 1099-Contract)
Load employee information from a text file selected by the user into an array consisting of Managers and Developers. The format of your text file should be something like this:
First Name, Last Name, Street Address, City, State, Zip, Employee Type (Manager or Developer), Cost Center (0 if Developer), Supervisor, Tax Type (NA if Manager)
There should be a separate line for each employee (only one line per employee with the fields above) and your file should contain at least 7 - 10 employee records. You should save the file with a .txt or .csv extension.
The UI should allow the user to select how many records to view (start at 3 and allow up to the total number of records loaded).
The following requirements detail the critical elements that will determine the grading criteria for your submission. Please see the rubric below these requirements.
The application should compile and run successfully
The application should display Inheritance (Steps 1 - 3 above).
The application should allow the user to load a text or csv file for processing (Step 4 above).
The application should load the text file elements into an array of employee records (Step 4 & 4a above).
The application should display records from the array. The number of records to display should be selected by the user. (Step 5 above).
Your application should contain comments to explain the data and process flow of your code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class empform extends JFrame implements
ActionListener
{
JLabel labl1, labl2, labl3, labl4, labl5, labl6, labl7, labl8;
JTextField txtf1, txtf2, txtf5, txtf6, txtf7;
JButton buton1, buton2;
JPasswordField p1, p2;
empform()
{
setVisible(true);
setSize(700, 700);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("empform Form in Java");
labl1 = new JLabel("empform Form in Windows Form:");
labl1.setForeground(Color.blue);
labl1.setFont(new Font("Serif", Font.BOLD, 20));
labl2 = new JLabel("Name:");
labl3 = new JLabel("Email-ID:");
labl4 = new JLabel("Create Passowrd:");
labl5 = new JLabel("Confirm Password:");
labl6 = new JLabel("Country:");
labl7 = new JLabel("State:");
labl8 = new JLabel("Phone No:");
txtf1 = new JTextField();
txtf2 = new JTextField();
p1 = new JPasswordField();
p2 = new JPasswordField();
txtf5 = new JTextField();
txtf6 = new JTextField();
txtf7 = new JTextField();
buton1 = new JButton("Submit");
buton2 = new JButton("Clear");
buton1.addActionListener(this);
buton2.addActionListener(this);
labl1.setBounds(100, 30, 400, 30);
labl2.setBounds(80, 70, 200, 30);
labl3.setBounds(80, 110, 200, 30);
labl4.setBounds(80, 150, 200, 30);
labl5.setBounds(80, 190, 200, 30);
labl6.setBounds(80, 230, 200, 30);
labl7.setBounds(80, 270, 200, 30);
labl8.setBounds(80, 310, 200, 30);
txtf1.setBounds(300, 70, 200, 30);
txtf2.setBounds(300, 110, 200, 30);
p1.setBounds(300, 150, 200, 30);
p2.setBounds(300, 190, 200, 30);
txtf5.setBounds(300, 230, 200, 30);
txtf6.setBounds(300, 270, 200, 30);
txtf7.setBounds(300, 310, 200, 30);
buton1.setBounds(50, 350, 100, 30);
buton2.setBounds(170, 350, 100, 30);
add(labl1);
add(labl2);
add(txtf1);
add(labl3);
add(txtf2);
add(labl4);
add(p1);
add(labl5);
add(p2);
add(labl6);
add(txtf5);
add(labl7);
add(txtf6);
add(labl8);
add(txtf7);
add(buton1);
add(buton2);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == buton1)
{
int x = 0;
String str1 = txtf1.getText();
String str2 = txtf2.getText();
char[] s3 = p1.getPassword();
char[] s4 = p2.getPassword();
String s8 = new String(s3);
String s9 = new String(s4);
String s5 = txtf5.getText();
String s6 = txtf6.getText();
String s7 = txtf7.getText();
if (s8.equals(s9))
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe", "sandeep", "welcome");
PreparedStatement ps = con.prepareStatement("insert into reg values(?,?,?,?,?,?)");
ps.setString(1, str1);
ps.setString(2, str2);
ps.setString(3, s8);
ps.setString(4, s5);
ps.setString(5, s6);
ps.setString(6, s7);
ResultSet rs = ps.executeQuery();
x++;
if (x > 0)
{
JOptionPane.showMessageDialog(buton1, "Data Saved Successfully");
}
}
catch (Exception ex)
{
System.out.println(ex);
}
}
else
{
JOptionPane.showMessageDialog(buton1, "Password Does Not Match");
}
}
else
{
txtf1.setText("");
txtf2.setText("");
p1.setText("");
p2.setText("");
txtf5.setText("");
txtf6.setText("");
txtf7.setText("");
}
}
public static void main(String args[])
{
new empform();
}
}