Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, This is an assignment for a first year Java course but I\'m having a lot of

ID: 3690520 • Letter: H

Question

Hi,

This is an assignment for a first year Java course but I'm having a lot of trouble with it. I'm still having issues with thinking of the "big picture", so any solution that I can look at as an example or some steps to help me complete this assignment would be great. Please help!

You will be creating a Payroll which will use Inheritance, Exceptions, and Aggregation. A GUI is optional.

Create a project folder which will be used to test your final project. It could be called something like PayrollManager. Create the following classes and interfaces:

Employee Class implements Serializable

private String name;             // Employee name

private String employeeNumber;   // Employee number

private String hireDate;         // Employee hire date

Default constructor puts null or 0 as appropriate

Initializer constructor initializes the private data and throws an InvalidEmployeeNumber Exception

write sets for all the private data and for the setEmpNumber throw an InvalidEmployeeNumber Exception if the String does not parse to an int or the number is out of the 0 to 9999 range

Write the toString method to return the data.

Write a main method within this class to test the Employee with valid and invalid data using try catch.

  

ProductionWorker Class extends Employee implements Serializable

// Constants for the day and night shifts.

   public static final int DAY_SHIFT = 1;

   public static final int NIGHT_SHIFT = 2;

   private int shift;         // The employee's shift

   private double payRate;    // The employee's pay rate

Default constructor calls super and puts null or 0 as appropriate

Initialzer constructor throws InvalidEmployeeNumber,   InvalidShift,   InvalidPayRate

The shift must be either 1 or 2 or throw an InvalidShift Exception

The payRate must be a positive number or throw an InvalidPayRate Exception

Write the toString method to return the data.

Write a main method within this class to test the ProductionWorker with valid and invalid data using try catch.

ShiftSupervisor Class extends Employee implements Serializable

private double salary; // Annual salary

        private double bonus;   // Annual bonus

                Default constructor puts null or 0 as appropriate

Initializer constructor initializes the private data and throws an InvalidEmployeeNumber Exception

Write the sets for this class which do not throw any additional Exceptions

Write the toString method to return the data.

Write a main method within this class to test the ShiftSupervisor with valid and invalid data using try catch.

TeamLeader Class extends ProductionWorker implements Serializable

private double monthlyBonus;           // Monthly bonus

private double requiredTrainingHours; // Required training hours

private double trainingHoursAttended; // Training hours attended

Default constructor puts null or 0 as appropriate

Initializer constructor initializes the private data and throws an InvalidEmployeeNumber Exception , InvalidShift Exception and InvalidPayRate Exception

You do not have to throw any new exceptions as they are thrown from the ProductionWorker super class.

Write the toString method to return the data.

Write a main method within this class to test the TeamLeader with valid and invalid data using try catch.

Payroll Class implements Serializable

private ArrayList <Employee> payroll;

The default constructor creates and empty ArrayList cabable of pointing to Employee objects

Create an addToPayroll method given an Employee type object

Create a removeFromPayroll method given an Employee String id. Overload this with given an Employee object. Return a string message to indicate success or failure.

Create a findInPayroll method given an Employee String id and returns an int value of the index or -1 if not there

Create a getEmployee method which given the String empId returns a copy of the employee or a null value if not found.

Write the toString method checking to make sure that payroll is not null before testing the size.

Write the writeToFile(String filename)throws FileNotFoundException,IOException

(because payroll is serializable you can use one statement to write out the whole payroll) return a String message.

Write the readFromFile(String filename)throws FileNotFoundException,

                                                        IOException,ClassNotFoundException

(because payroll is Serializable you can use one statement to read into the whole payroll but must cast the returned payroll as (ArrayList<Employee>) return a String message.

Write a main method within this class to test the Payroll class by adding, removing, storing and retrieving Employees.

Test your PayrollManager class as an interactive interface allowing the User to input data. This class handles the output which the other classes return information.

Explanation / Answer

/**** Employee.java ***/

/***EmployeeException.java***/

/**EmployeeManager.java ***/

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.TableColumn;

public class EmployeeManager
{
   private static EmployeeManager app;
   private JMenuBar mainMenu;
    private JFrame mainWindow;
    private JTable table;
    private boolean unsavedChangesMade = false;
    private int currentSelectedRow = -1;
    private final int WINDOW_WIDTH = 440; // Window width
    private final int WINDOW_HEIGHT = 145; // Window height

    private int[] columnWidths = {130, 120, 65, 65, 80, 50, 80, 80};
    TableColumn column = null;
    private JMenuItem exitItem;
   private JMenuItem helpItem;
   private AbstractButton addItem;
   private JMenuItem openItem;
   private JMenuItem closeItem;
   private JMenuItem saveItem;
   private AbstractButton saveAsItem;
   private AbstractButton editItem;
   private JMenuItem deleteItem;
   private JMenuItem newItem;
   
    // Constructor
   
    public EmployeeManager()
    {  
        //buildArrays();
        //fileChooser();
        mainManager();
        //adderScreen();
        //fileBrowser();
    }              
   

    public void mainManager()
    {
       mainWindow = new JFrame("Employee Manager - Choose a File");
        // Display a title
       mainWindow.setSize(WINDOW_WIDTH + 300, WINDOW_HEIGHT + 200);
       mainWindow.setLocationRelativeTo(null);
       // Specify an action for the close button.
       mainWindow.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
       // Create a BorderLayout manager.
       mainWindow.setLayout(new BoxLayout(mainWindow.getContentPane(), BoxLayout.Y_AXIS));
       mainWindow.addWindowListener(new WindowsListener());
      
       buildDisplayPanel();
      
       mainWindow.setResizable(false);
       mainWindow.setVisible(true);
   }
   

    public void buildDisplayPanel()
    {
        //DefaultTableModel model = new DefaultTableModel();
        //table = new JTable(model);
        //JPanel tablePanel = new JPanel();
        //tablePanel.setSize(WINDOW_WIDTH + 500, WINDOW_HEIGHT - 20);
        mainMenu = new JMenuBar();
        JMenu file = new JMenu("File");
        JMenu employee = new JMenu("Employee");
       JMenu help = new JMenu("Help");
      
       openItem = new JMenuItem("Open");
       openItem.setMnemonic(KeyEvent.VK_O);
       openItem.addActionListener(new mainMenuListener());
      
       newItem = new JMenuItem("New");
       newItem.setMnemonic(KeyEvent.VK_N);
       newItem.addActionListener(new mainMenuListener());
      
       closeItem = new JMenuItem("Close");
       closeItem.setMnemonic(KeyEvent.VK_C);
       closeItem.addActionListener(new mainMenuListener());
      
       saveItem = new JMenuItem("Save");
       saveItem.setMnemonic(KeyEvent.VK_S);
       saveItem.setEnabled(false);
       saveItem.addActionListener(new mainMenuListener());
      
       saveAsItem = new JMenuItem("Save As");
       saveAsItem.setMnemonic(KeyEvent.VK_A);
       saveAsItem.setEnabled(false);
       saveAsItem.addActionListener(new mainMenuListener());
      
       exitItem = new JMenuItem("Exit");
       exitItem.setMnemonic(KeyEvent.VK_X);
       exitItem.addActionListener(new mainMenuListener());
      
       addItem = new JMenuItem("Add");
       addItem.setMnemonic(KeyEvent.VK_A);
       addItem.setEnabled(false);
       addItem.addActionListener(new mainMenuListener());
      
       editItem = new JMenuItem("Edit");
       editItem.setMnemonic(KeyEvent.VK_E);
       editItem.setEnabled(false);
       editItem.addActionListener(new mainMenuListener());
      
       deleteItem = new JMenuItem("Delete");
       deleteItem.setMnemonic(KeyEvent.VK_D);
       deleteItem.setEnabled(false);
       deleteItem.addActionListener(new mainMenuListener());
      
       helpItem = new JMenuItem("Help");
       helpItem.setMnemonic(KeyEvent.VK_H);
       helpItem.addActionListener(new mainMenuListener());
      
       file.add(openItem);
       file.add(newItem);
       file.add(saveItem);
       file.add(saveAsItem);
       file.add(closeItem);
       file.add(exitItem);
      
       employee.add(addItem);
       employee.add(editItem);
       employee.add(deleteItem);
      
       help.add(helpItem);
      
       mainMenu.add(file);
       mainMenu.add(employee);
       mainMenu.add(help);
      
        table = TableManagement.getTable();
       JScrollPane scrollPane = new JScrollPane(table);
        table.setFillsViewportHeight(true);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.getTableHeader().setReorderingAllowed(false);
        table.getTableHeader().setResizingAllowed(false);
        table.getSelectionModel().addListSelectionListener(new RowListener());
        for (int i = 0; i < 8; i++) {
            column = table.getColumnModel().getColumn(i);
            column.setPreferredWidth(columnWidths[i]);
        }
       
        mainWindow.setJMenuBar(mainMenu);
        mainWindow.add(scrollPane);
       
       
    }
   
    public void setVisible() {
        mainWindow.setVisible(true);
    }

   
    private class WindowsListener implements WindowListener
    {
       @Override
       public void windowActivated(WindowEvent e)
       {  
       }
       @Override
       public void windowClosed(WindowEvent e)
       {
           if (unsavedChangesMade)
           {
               int selection = 0;
               selection = JOptionPane.showConfirmDialog(null, "<HTML>Changes were made to this "
                       + "document that have not<P> been saved. Would you like to save them now?"
                       + "</HTML>", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION);
               if (selection == JOptionPane.YES_OPTION)
               {
                   FileManagement.saveData();
                   System.exit(0);
               }
               if (selection == JOptionPane.NO_OPTION)
               {
                   System.exit(0);
               }
           }
           else
               System.exit(0);
       }  
       @Override
       public void windowDeactivated(WindowEvent e)
       {  
       }
       @Override
       public void windowDeiconified(WindowEvent e)
       {  
       }
       @Override
       public void windowIconified(WindowEvent e)
       {  
       }

       @Override
       public void windowOpened(WindowEvent e)
       {  
       }
       @Override
       public void windowClosing(WindowEvent e) {
           if (unsavedChangesMade)
           {
               int selection = 0;
               selection = JOptionPane.showConfirmDialog(null, "<HTML>Changes were made to this "
                       + "document that have not<P> been saved. Would you like to save them now?"
                       + "</HTML>", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION);
               if (selection == JOptionPane.YES_OPTION)
               {
                   FileManagement.saveData();
                   System.exit(0);
               }
               if (selection == JOptionPane.NO_OPTION)
               {
                   System.exit(0);
               }
           }
           else
               System.exit(0);
          
       }
       
    }
   

   
    private class RowListener implements ListSelectionListener
    {
       @Override
       public void valueChanged(ListSelectionEvent e)
       {
           if (table.getSelectedColumn() >= 0 && table.getSelectedRow() >= 0 && table.getSelectedRow() != currentSelectedRow)
           {
               if (table.getValueAt(table.getSelectedRow(), 0) != null)
               {
                   editItem.setEnabled(true);
                   deleteItem.setEnabled(true);
               }
               else
               {
                   editItem.setEnabled(false);
                   deleteItem.setEnabled(false);
               }
               currentSelectedRow = table.getSelectedRow();
           }
          
       }
       
    }
   

   private class mainMenuListener implements ActionListener {

       @Override
       public void actionPerformed(ActionEvent e) {
           if (e.getSource() == openItem){
               mainWindow.setVisible(false);
               FileManagement.openWindow();
               if (FileManagement.isLoaded()) {
                   addItem.isEnabled();
                   mainWindow.setTitle("Employee Manager - " + FileManagement.getFileLocation());
               }
               mainWindow.setVisible(true);
           }
           if (e.getSource() == newItem) {
               mainWindow.setVisible(false);
               FileManagement.saveAsWindow();
               mainWindow.setVisible(true);
               addItem.setEnabled(true);
           }
           if (e.getSource() == saveAsItem){
               mainWindow.setVisible(false);
               FileManagement.saveAsWindow();
               mainWindow.setVisible(true);
           }
           if (e.getSource() == closeItem){
               if (unsavedChangesMade)
               {
                   int selection = 0;
                   selection = JOptionPane.showConfirmDialog(null, "<HTML>Changes were made to this "
                           + "document that have not<P> been saved. Would you like to save them now?"
                           + "</HTML>", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION);
                   if (selection == JOptionPane.YES_OPTION)
                   {
                       FileManagement.saveData();
                       app = new EmployeeManager();
                   }
                   if (selection == JOptionPane.NO_OPTION)
                       app = new EmployeeManager();
               }
               else
                   app = new EmployeeManager();
           }
           if (e.getSource() == saveItem)
               FileManagement.saveData();
           if (e.getSource() == exitItem)
               System.exit(0);
           if (e.getSource() == addItem)
           {
               mainWindow.setVisible(false);
               ModifyWindow.showAddWindow();
               mainWindow.setVisible(true);
           }
           if (e.getSource() == editItem)
           {
               mainWindow.setVisible(false);
               ModifyWindow.showEditWindow(currentSelectedRow);
               mainWindow.setVisible(true);
           }
          
           if (e.getSource() == helpItem)
               JOptionPane.showMessageDialog(null, "Select an animal from the list, then select" +
                                                   " a choice from the combo box to see an image");
          
          
       }
      
   }
  
    public static void main(String[] args)
    {
       app = new EmployeeManager();
   }
}

/*** FileManagement.java***/

/***ProductionWorker.java***/

/***ShiftSupervisor.java ***/

/*** ShiftSupervisorException.java***/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote