Portfolio Title





 

 

Student Portfolio >> Index >> Coding >> JAVA Assignment

 

// Kerstin Kegel 040504694 Java Assignment EMPLOYEE
 public class Employee
   {
   protected String name;
   protected double wage;
   protected int hireYear;
         
 public Employee( String empName, double empwage, int empHireYear )
   {
   name = empName;
   wage = empwage;
   hireYear = empHireYear;
   }
         
 public Employee( )
   {
   name = "Kerstin Kegel";
   wage = 80000.00;
   hireYear = 2001;
   }
         
 public String getName() // Get Employee Name
   {
   return name;
   }
         
 public double getwage() // Get wage
   {
   return wage;
   }
         
 public int getHireYear() // Get year of employment
   {
   return hireYear;
   }
         
 public void setName(String varName) // Set Employee Name
   {
   name = varName;
   }
         
 public void setwage(double varwage) // Set wage
   {
   wage = varwage;
   }
         
 public void setHireYear( int varHireYear ) // Set year of empl.
   {
   hireYear = varHireYear;
   }
         
 public void display()
   {
   System.out.println( "Employee Name = " + name + " wage = " + wage + " Hire Year = " + hireYear);
   }
         
 
 public void raisewage(double byPercent)
   {
   wage = wage + (wage * byPercent);
   }
// Kerstin Kegel 040504694 JAVA Assignment EMPLOYEEUPDATE
 import java.awt.* ;
   import java.awt.event.* ;
   import javax.swing.* ;
   import java.text.*;
   import java.util.*;
   import java.lang.String;
         
 
 public class EmployeeUpdate extends JFrame implements ActionListener
   {
   private JTextField txtfirstn, txtwage, txtyearhired;
   private JButton displayButton, clearButton;
   private JLabel lblfirstn, lblwage, lblyearhired, lblhead;
   private Employee empinstance = new Employee();
   private String NameV;
   private double wagesV;
   private int yearhirev;
   public EmployeeUpdate()
 {
   super( "JAVA - KERSTIN KEGEL 040504694");
 Container formcont = getContentPane();
   formcont.setLayout(new BorderLayout(5,5));
 JPanel centerPanel = new JPanel();
   centerPanel.setLayout( new GridLayout(3,1,0,5));
 JPanel rightPanel = new JPanel();
   rightPanel.setLayout( new GridLayout(3,2,0,5));
 JPanel bottomPanel = new JPanel();
   bottomPanel.setLayout( new GridLayout(1,0,5,5));
 JPanel leftPanel = new JPanel();
   leftPanel.setLayout( new GridLayout(1,1,20,5));
 ActionEventHandler handler = new ActionEventHandler();
 JMenuBar bar = new JMenuBar();
   setJMenuBar(bar);
 JMenu fileMenu = new JMenu( "File" );
   fileMenu.setMnemonic( 'F' );
 JMenuItem raiseSal = new JMenuItem( "Raise 15%" );
   raiseSal.setMnemonic( 'R' );
   raiseSal.addActionListener(this);
   fileMenu.add(raiseSal);
 JMenuItem exitItem = new JMenuItem( "Exit" );
   exitItem.setMnemonic( 'X' );
   exitItem.addActionListener(this);
 fileMenu.add(exitItem);
   bar.add(fileMenu);
 lblfirstn = new JLabel("First Name: ");
   lblfirstn.setToolTipText("First Name");
   centerPanel.add(lblfirstn);
   txtfirstn = new JTextField("Enter the First Name", 31);
   rightPanel.add(txtfirstn);
 lblwage = new JLabel("Wage: ");
   lblwage.setToolTipText("Wage");
   centerPanel.add(lblwage);
   txtwage = new JTextField("0.00");
   rightPanel.add(txtwage);
 lblyearhired = new JLabel();
   lblyearhired.setText("Year hired ");
   lblyearhired.setToolTipText("Enter year Hired");
   centerPanel.add(lblyearhired);
   txtyearhired = new JTextField("2004", 4);
   rightPanel.add(txtyearhired);
 lblhead = new JLabel(" ");
   leftPanel.add(lblhead);
 displayButton = new JButton("Display");
   bottomPanel.add(displayButton);
 clearButton = new JButton("Clear");
   bottomPanel.add(clearButton);
 formcont.add(centerPanel,BorderLayout.CENTER);
   formcont.add(leftPanel,BorderLayout.WEST);
   formcont.add(rightPanel,BorderLayout.EAST);
   formcont.add(bottomPanel,BorderLayout.SOUTH);
 txtfirstn.addActionListener(handler);
   txtwage.addActionListener(handler);
   txtyearhired.addActionListener(handler);
 displayButton.addActionListener(handler);
   clearButton.addActionListener(handler);
 setSize(700, 300);
 show();
   }
         
 
 public static void main( String args[] )
   {
   EmployeeUpdate app = new EmployeeUpdate();
         
 app.addWindowListener (
   new WindowAdapter()
   { public void windowClosing( WindowEvent e)
   {
   System.exit(0) ;
   }
   }
   );
   }
 
 private class ActionEventHandler implements ActionListener
   {
   public void actionPerformed( ActionEvent e )
   {
   String s = "" ;
   if ( e.getSource() == txtfirstn )
   s = "first name: " + e.getActionCommand();
   else if ( e.getSource() == txtwage )
   s = "salary: " + e.getActionCommand();
   else if ( e.getSource() == txtyearhired )
   s = "hire year: " + txtyearhired.getText();
 if ( e.getSource() == displayButton )
   {
   txtfirstn.setText(empinstance.getName());
   txtwage.setText(Double.toString(empinstance.getwage()));
   txtyearhired.setText(Integer.toString(empinstance.getHireYear()));
   }
 else if ( e.getSource() == clearButton )
   {
 txtfirstn.setText("");
   txtwage.setText("");
   txtyearhired.setText("");
   }
         
 else
         
 {
 if ( (txtfirstn.getText().trim().length() == 0) || (txtwage.getText().trim().length() == 0) || (txtyearhired.getText().trim().length() == 0) )
   {
   JOptionPane.showMessageDialog( null, "Some information are missing! Please fill them up to save the details.");
   }
 else
   {
   NameV = txtfirstn.getText();
   wagesV = Double.parseDouble(txtwage.getText());
   yearhirev = Integer.parseInt(txtyearhired.getText());
 empinstance = new Employee(NameV, wagesV, yearhirev);
   };
 }
 }
 }
 
 public void actionPerformed(ActionEvent evt)
   {
   String mnulabel = "" ;
   if ( evt.getSource() instanceof JMenuItem )
   {
   mnulabel = evt.getActionCommand() ;
   if ( mnulabel == "Exit" )
   {
   int sagot = JOptionPane.showConfirmDialog ( this, "Exit program?" );
   if ( sagot == JOptionPane.YES_OPTION )
   {
   System.exit( 0 );
   }
 }
 else if ( mnulabel == "Raise 15%" )
   {
 empinstance.raisewage(.15);
   txtfirstn.setText(empinstance.getName());
   txtwage.setText(Double.toString(empinstance.getwage()));
   txtyearhired.setText(Integer.toString(empinstance.getHireYear()));
   }
 }
 }
 }
         
 
 
 
 
 

        
 
        
 
<< Back                                                                                                                                                                                        Forward >> 

Coding | Website Scripting | Visual Design | Instructional Design | Website Design | Website Design Tools

 

Copyright 2005 Kerstin Kegel