java program help Create a class called Employee whose objects are records for a
ID: 3646644 • Letter: J
Question
java program helpCreate a class called Employee whose objects are records for an employee. This class will be a derived class of the class Person which you will have to create your own and compile. An employee record has an employee's name (inherited from the class Person), an annual salary represented as a single value of type double, a year the employee started work as a single value of type integer and a national insurance number, which is a value of type String.
Your class should have a reasonable number of constructors and accessor methods, and other necessary methods. Write your own main program to fully test your class definition.
Explanation / Answer
class ConnectData { private Connection connection = null; private Statement statement = null; private ResultSet resultSet = null; private PreparedStatement prepareSet = null; private String driver = "org.hsqldb.jdbcDriver"; private String URL = "jdbc:hsqldb:file:test"; ConnectData() { try { Class.forName(driver); connection = DriverManager.getConnection(URL); } catch (ClassNotFoundException SQLe) { JOptionPane.showMessageDialog(null, SQLe.toString(), "Error", JOptionPane.ERROR_MESSAGE); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.toString(), "Error", JOptionPane.ERROR_MESSAGE); } //start photo class Photo extends JTextField { Image img; public Image Photo (String ph) { if (ph == null) JOptionPane.showMessageDialog(null, "No Data", "Error", JOptionPane.ERROR_MESSAGE); else img = this.getToolkit().getImage(ph); return img; } public void paint (Graphics g) { g.drawImage(img, 0, 0, 200, 200, this); } } else if(stringChoose=="BROWSE IMAGE") { int option = myFileChooser.showOpenDialog(Employee.this); String dir = myFileChooser.getCurrentDirectory().toString(); myStrPhoto = dir+"\"+((myFileChooser.getSelectedFile() !=null)? myFileChooser.getSelectedFile().getName():"nothing"); if (option == JFileChooser.APPROVE_OPTION) { myFoto.setIcon(new ImageIcon(photo.Photo(myStrPhoto))); } } try{ String sql_tambah = "INSERT INTO Employee "+ "VALUES('"+ a +"','"+ b +"','"+c+"','"+d+"','"+myStrPhoto+"')"; dt = new ConnectData(); dt.prepareSet(sql_tambah); tampilData(); clearText(); }catch(Exception se){ JOptionPane.showMessageDialog(null,"Data Exist"); } try{ String sql_ubah = "UPDATE Employee "+ "SET Name = '"+ bb +"',Adress = '"+ cc +"',Note='"+dd+"',Photo='"+myStrPhoto+"' WHERE NoID = '"+ aa +"'"; dt = new ConnectData(); dt.prepareSet(sql_ubah); tampilData(); clearText(); }catch(Exception se){ JOptionPane.showMessageDialog(null,"Failed to Update "+se); } MouseAdapter ma = new MouseAdapter(){ public void mouseClicked(MouseEvent me){ ambilData(); myButtoninput.setEnabled(false); myButtonedit.setEnabled(true); myButtondelete.setEnabled(true); myButtonkosong.setEnabled(true); } }; KeyAdapter ka = new KeyAdapter(){ public void keyPressed(KeyEvent ke){ ambilData(); myButtoninput.setEnabled(false); myButtonedit.setEnabled(true); myButtondelete.setEnabled(true); myButtonkosong.setEnabled(true); } }; myDataTable.addKeyListener(ka); myDataTable.addMouseListener(ma); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.