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

Objectives: The focus of this assignment is the use Swing components to create a

ID: 3582283 • Letter: O

Question

Objectives: The focus of this assignment is the use Swing components to create a simple GUI based program

Program Description:

The final portion of the project will be to create a GUI interface for the user, getting rid of the text-based menu system. The application will use the EmployeeManager in the same way the EmployeeDriver did, but provide an easier interface.

A total of fifteen classes are required.

EmployeeFrame – Java Swing Frame (starter code provided)

EmployeeFrameDriver - Provided

Queue – (From previous assignment)

ListNode – (From previous assignment)

LikedList – Implementation of the LinkedList data structure of Comparables

EmptyListException – (From previous assignment)

ArrayList (From previous assignment)

InvalidEmployeeNumberException (From previous assignment)

InvalidSizeException (From previous assignment)

MaximumCapacityException (From previous assignment)

Employee (Altered from previous assignment)

HourlyEmployee (From previous assignment)

SalaryEmployee (From previous assignment)

CommissionEmployee (From previous assignment)

EmployeeManager (Altered from previous assignment)

The final result will look something like this:

We will no longer be outputting to the console through System.out, rather a JTextArea is provided for satisfying output requests and messages. This will in effect be our new “console”. In order to take advantage of this, there are some small changes that need to be made to the EmployeeManager. Some of the EmployeeManager’s methods output directly to System.out, we do not want that any more since all output should be in the JTextArea for the user.

Changes to EmployeeManager

Changes for removing System.out output

EmployeeManager

- employees : ArrayList<Employee>

- employeeMax : final int = 10

- hourlyList : LinkedList<Employee>

- salaryList : LinkedList<Employee>

- commissionList : LinkedList<Employee>

- vacationRequests : Queue<Employee>

<<constructor>> EmployeeManager()

+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) throws InvalidEmployeeNumberException

+ removeEmployee( index : int)

+ listAll() : String

+ listHourly() : String

+ listSalary() : String

+ listCommision() :String

+ resetWeek()

+ calculatePayout() : double

+ getIndex( empNum : int ) : int

+ annualRaises()

+ holidayBonuses() : double

+ increaseHours( index : int, amount : double) : boolean

+ increaseSales( index : int, amount : double) : boolean

+ findAllBySubstring(find : String) : Employee[]

- RabinKarp(name : String, find : String) : int

- stringHash(s : String) : int

- charNumericValue(c : char) : int

- RabinKarpHashes(s : String, hashes : int[], pos : int, length : int) : int

- linearSearchRecursive(nameHashes : int[], findHash : int, pos : int) : int

+ sort()

+ addRequest(empNum : int) : boolean

+ viewNextRequest() : Employee

+ grantNextRequest() : Employee

+ outputRequests() : String

+ loadEmployees(employeeFile : String, requestFile : String) boolean

+saveEmployees(employeeFile : String, requestFile : String) boolean

+processUpdates(fileName : String) boolean

Changes detailed on following page

list methods

Instead of outputting the toString of the ArrayList and LinkedLists in the methods, the String is now returned. If there are no Employees listAll() will return the String, “No Employees”. If there are no Employees of a specific type, its cooresponding list method will return a String indicating that, for example, “No Hourly Employees”.

public double holidayBonuses()

This will still return the total of all bonuses, but remove the output of the individual bonuses in the method.

public boolean increaseHours/Sales()

Both of these methods will return a true if they are successful, false if they are not. Remove output to System.out.

public String outputRequests()

Similar change as the list methods. Returns the String of requests. If there are no requests returns the String “No vacation requests”.

EmployeeFrame

EmployeeFrame extends JFrame

-       em : EmployeeManager

-       employeeTypeCombo : JComboBox<String>

-       firstField : JTextField

-       lastField : JTextField

-       middleCombo : JComboBox<Character>

-       genderCombo : JComboBox<Character>

-       employeeNumberField : JTextField

-       fullTimeRadio : JRadioButton

-       partTimeRadio : JRadioButton

-       amountField : JTextField

-       addEmployeeButton : JButton

-       employeeNumberRemoveField : JTextField

-       removeButton : JButton

-       employeeNumberUpdateField : JTextField

-       amountUpdateField : JTextField

-       updateHourlyButton : JButton

-       updateCommissionButton : JButton

-       updateFromFileButton : JButton

-       payoutButton : JButton

-       bonusButton : JButton

-       raisesButton : JButton

-       resetWeekButton : JButton

-       viewRequestButton : JButton

-       addRequestButton : JButton

-       grantRequestButton : JButton

-       sortPrintButton : JButton

-       printHourlyButton : JButton

-       printSalaryButton : JButton

-       printCommissionButton : JButton

-       findButton : JButton

-       exitButton : JButton

-       console : JTextArea

<<constructor>> EmployeeFrame()

-       createMiddleOptions() : Character[]

The EmployeeFrame has the following private inner class. This inner class will be the Event Handler for all of the EmployeeFrame’s buttons. Only the JButtons of the EmployeeFrame need a listener, no other components have a listener.

ButtonHandler implements ActionListener

+ actionPerformed(event : ActionEvent)

Starter code has been provided. This declares all of the data members, gives you the createMiddleOptions method (Used to quickly create an array of Characters A-Z for the middle initial Combo Box, and the set up of the JTextArea console.

Constructor

Sets up the Frame and creates all components. Creates the EmployeManager object the application will be manipulating. As you can see above, the Frame is logically split up into sections using panels. For each of these sections create a JPanel, set its Layout to a Flow Layout and give it a black boarder. This can be done like this:

              JPanel addPanel = new JPanel();

              addPanel.setLayout(new FlowLayout());

              addPanel.setBorder(BorderFactory.createLineBorder(Color.black));

Then create all of the components for that panel and add them to the panel in the order in which they appear, then add the panel to the Frame. Get your application to look as close to the example as possible noting the following JTextField sizes below as well as the default text.

JTextField Sizes

Name fields: 15

Employee Number fields: 5

Amount fields: 10

The Full/Part JRadioButtons belong to a ButtonGroup to ensure only one is selected at one time.

Also note that each section has a JLabel as the first component, do not forget to create and add these as well. They are not class wide data members since they do not need to be further referenced by us. We need access to the other components in the handler, so those are class wide.

Once all of the components have been created and added, attempt to call upon the EmployeeManager’s loadEmployees with the file name, “employees.ser” and “requests.dat”. If successful output “Employees Loaded” to the console, otherwise “Employees Not Loaded”

Notes on JTextArea console

Whenever you perform an action that causes the console to be updated clear the previous contents to avoid clutter. These two JTextArea methods will be helpful for manipulating the console:

public void setText(String t)

Sets the text of the JTextArea to the passed String, removing the current contents.

Public void append(String t)

Appends the passed String to the current contents of the JTextArea.

ButtonHandler

Your EmployeeFrame constructor only needs to create ONE instance of the ButtonHandler, since the same Handler will be capable of handling all buttons. Add the same handler to all JButton components.

Note on input components

Some of the operations require altering the contents of one or more of the JTextFields, JComboBoxes, and/or JRadioButtons. Once the action has occurred reset the associated components to their starting values. For example, the user enters all of the information for a new Employee and hits the “Add Employee” button. Whether or not it was successful set all of the components back. firstField is set back to the String, “First”, lastField to, “Last”, middleCombo to ‘A’, genderCombo to ‘M’, etc.

Following is what should happen if the JButtons are pressed. These actions go in the ButtonHandler’s actionPerformed() method as demonstrated in class. First determine which button triggered the event by using the event’s getSource() method, then perform the correct actions for that button.

addEmployeeButton

Using the user inputs from the Add Employee section, call upon the EmployeeManager’s addEmployee. If the Employee is added successfully output “Employee Added” to the console. If either an InvalidEmployeeNumberException or NumberFormatException occurs output “Invalid Employee Number to the console. Reset the user inputs back to defaults.

removeButton

Attempt to remove the Employee given in the section. If successful output, “Employee (EmployeeNumber) Removed”. If the Employee does not exist or a NumberFormatException occurs output “No Such Employee”. Reset the Employee number field.

updateHourlyButton/updateCommissionButton

Using the values in the Employee number and amount field attempt to call upon the increaseHours/increaseSales method. If a NumberFormatException occurs in parsing the Employee number or amount output “Invalid Employee Number” or “Invalid Amount”, respectively. If the Employee does not exist output “No Such Employee”. If the call to increaseHours/increaseSales returns false, this means the index passed is not to the correct type of Employee, output that information to the console as either, “Employee Not Hourly” or “Employee Not Commission”, respectively.

If the action is successful output one of the following depending on the button pressed, “(Employee Number) increased by (Amount) hours” or “(Employee Number) increased by (Amount) sales”. The amount should be formatted to show exactly 2 decimal points.

updateFromFileButton

To choose the file to use we will use the JFileChooser, the majority of the code is provided here:

JFileChooser fileChooser = new JFileChooser(new File("."));

                           int fileRet = fileChooser.showOpenDialog(null);

      

                           if(fileRet == JFileChooser.APPROVE_OPTION)

                           {

                                  if(em.processUpdates(fileChooser.getSelectedFile().getAbsolutePath()))

                                  {

                                         //Output "Updates Processed Successfully" to console

                                  }

                                  else

                                  {

                                         //Output "Updates Not Processed" to console

                                  }

                           }

payoutButton

Using EmployeeManager’s calculatePayout() output the payout to the console in the format, “Total weekly payout is (Amount)”

bonusButton

Using EmployeeManager’s holidayBonuses() output the bonus amount to the console in the format, “Total holiday bonus is (Amount)”

raisesButton

Applies the EmployeeManager’s annualRaises() and outputs “Annual Raises Applied”.

resetWeekButton

Applies the EmployeeManager’s resetWeek() and outputs “Weekly values reset”.

viewRequestButton

Outputs the String returned by EmployeeManager’s outputRequests to the console. If there is a non-null Next Request output it to the console as well in the format, “(Employee) will receive next request”

addRequestButton

Prompt user for an Employee number using JOptionPane’s showInputDialog with the text “Enter Employee Number”

Attempts to add Employee with the given number to the vacation Queue. If a NumberFormatException occurs when parsing the input output “Invalid Employee Number to the console. If the Employee does not exist output “No Such Employee” to the console. If the action is successful output “Employee (Employee Number) added to vacation queue” to the console.

grantRequestButton

Attempt to grant next vacation request. If there is no Employee in the Queue output “No vacation requests” to console, if it succeeds output “(Employee) granted vacation request”

sortPrintButton

Sort the Employees using the EmployeeManager’s sort() then output all Employees to the console.

printHourlyButton/printSalaryButton/printCommissionButton

Output the appropriate Employees to the console.

findButton

Prompt user for a search String using JOptionPane’s showInputDialog with the text “Enter Search String”

If nothing is entered do not try to search. If a String is entered us EmployeeManager’s findAllBySubstring() to output matches to the console. If an InvalidCharacterException is thrown output “Invalid character found in search” to the console.

exitButton

Call EmployeeManager’s saveEmployees with the files “employees.ser” and “requests.dat” and terminate the program by calling System.exit(0)

Testing

All functionality will be retested for the final version of the project, so if you did not fix problems from previous iterations be sure to update them. Testing will basically be the same as previous versions, the only differences being the way input is done through the GUI and output goes to the JTextField.

Other Notes:

-       Import classes to files as necessary

-       Be sure to format your output to the console as it is described in this document

-       Format all amounts to exactly 2 decimal places

-       Each action should clear the previous contents of the console before performing its own output

-       The only way the current data is saved is by hitting the “Save/Exit” button. If in testing you made changes to the Employees that you DO NOT want to save, closing the application with the red X will exit without saving

EmployeeManager

- employees : ArrayList<Employee>

- employeeMax : final int = 10

- hourlyList : LinkedList<Employee>

- salaryList : LinkedList<Employee>

- commissionList : LinkedList<Employee>

- vacationRequests : Queue<Employee>

<<constructor>> EmployeeManager()

+ addEmployee( type : int, fn : String, ln : String, m : char, g : char, en : int, ft : boolean, amount : double) throws InvalidEmployeeNumberException

+ removeEmployee( index : int)

+ listAll() : String

+ listHourly() : String

+ listSalary() : String

+ listCommision() :String

+ resetWeek()

+ calculatePayout() : double

+ getIndex( empNum : int ) : int

+ annualRaises()

+ holidayBonuses() : double

+ increaseHours( index : int, amount : double) : boolean

+ increaseSales( index : int, amount : double) : boolean

+ findAllBySubstring(find : String) : Employee[]

- RabinKarp(name : String, find : String) : int

- stringHash(s : String) : int

- charNumericValue(c : char) : int

- RabinKarpHashes(s : String, hashes : int[], pos : int, length : int) : int

- linearSearchRecursive(nameHashes : int[], findHash : int, pos : int) : int

+ sort()

+ addRequest(empNum : int) : boolean

+ viewNextRequest() : Employee

+ grantNextRequest() : Employee

+ outputRequests() : String

+ loadEmployees(employeeFile : String, requestFile : String) boolean

+saveEmployees(employeeFile : String, requestFile : String) boolean

+processUpdates(fileName : String) boolean

Explanation / Answer

HourlyEmployee.java


import exceptions.InvalidEmployeeNumberException;
import java.util.Scanner;

public class HourlyEmployee extends Employee
{
    private double wage, hoursWorked;

    public HourlyEmployee (String fn, String ln, char m, char g, int empNum, boolean ft, double w) throws InvalidEmployeeNumberException
    {
        super (fn, ln, m, g, empNum, ft);

        wage = w;

        hoursWorked = 0.0;
    }

    public void increaseHours(double hours)
    {
        hoursWorked += hours;

        while (hoursWorked < 0)
        {
            System.out.print("Error. The number of hours worked must be great than 0. Please re-enter: ");
        }
    }

    public String toString()
    {
        return String.format("%sWage: %.2f Hours Worked: %.2f ", super.toString(), wage, hoursWorked);
    }


    public double calculateWeeklyPay()
    {
        if (hoursWorked > 40)
            return (double)(((hoursWorked - 40) * (wage * 2) + ((wage) * 40)) * 100) / 100;
        else
            return (double)((wage * hoursWorked) * 100) /100;
    }

    public void annualRaise()
    {
        wage = (double)(((wage) + ((wage) * 0.05)) * 100 - 0.5) / 100;
    }

    public double holidayBonus()
    {
        return (double)((40 * wage) * 100) / 100;
    }
    public void resetWeek()
    {
        hoursWorked = 0.0;
    }
}

SalaryEmployee.java


import exceptions.InvalidEmployeeNumberException;
import employeeType.employee.Employee;

public class SalaryEmployee extends Employee
{
    private double salary;

    public SalaryEmployee(String fn, String ln, char m, char g, int empNum, boolean ft, double salary) throws InvalidEmployeeNumberException
    {
        super (fn, ln, m, g, empNum, ft);
        this.salary = salary;
    }

    @Override
    public String toString()
    {
        return String.format("%sSalary: %.2f ", super.toString(), salary);
    }

    public double calculateWeeklyPay()
    {
        return (double)((salary / 52) * 100) / 100;
    }

    public void annualRaise()
    {
        salary = (double)((salary + (salary * 0.06)) * 100) / 100;
    }

    public double holidayBonus()
    {
        return (double)((0.03 * salary) * 100) / 100;
    }

    public void resetWeek()
    {
    }
}

Queue.java


import dataStructures.LinkedList;
import dataStructures.ListNode;

public class Queue<E extends Comparable<E>>
{
    private LinkedList<E> list;
  
    public Queue()
    {
        this("name");          
    }

    public Queue(String name)
    {
        list = new LinkedList<E>(name);
    }

    public void enqueue(E item)
    {
        list.insertAtBack(item);

    }

    public E dequeue()
    {
        return list.removeFromFront();
    }

    public int lengthIs()
    {
        return list.lengthIs();
    }

    public E peek()
    {
        return list.getItem(0);
    }

    public String toString()
    {
        return list.toString();
    }

    public Boolean isEmpty()
    {
        return list.isEmpty();
    }

    public void clear()
    {
        list.clear();
    }
}


LinkedListTest.java

import dataStructures.LinkedList;
import exceptions.EmptyListException;

public class LinkedListTest
{
       public static void main(String[] args)
       {
               LinkedList<Integer> myList = new LinkedList<Integer>("Integer List");

               printLengthAndList(myList);

               System.out.println("Populating from front");

               for(int x = 0; x < 5; x++)
               {
                       myList.insertAtFront(x);
               }

               printLengthAndList(myList);

               System.out.println("Populating from back");

               for(int x = 0; x < 5; x++)
               {
                       myList.insertAtBack(x);
               }

               printLengthAndList(myList);

               System.out.println("Sorting");
               myList.sort();

               printLengthAndList(myList);

               System.out.println("Removing from front, then back");

               try
               {
                       myList.removeFromFront();
               }
               catch(EmptyListException ELE)
               {
                       System.out.print(ELE);
               }

               try
               {
                       myList.removeFromBack();
               }
               catch(EmptyListException ELE)
               {
                       System.out.print(ELE);
               }

               printLengthAndList(myList);

               try
               {
                       if(myList.findAndRemove(5))
                       {
                               System.out.println("5 removed");
                       }
                       else
                       {
                               System.out.println("5 not removed");
                       }
               }
               catch(EmptyListException ELE)
               {
                       System.out.println(ELE);
               }

               printLengthAndList(myList);

               try
               {
                       if(myList.findAndRemove(0))
                       {
                               System.out.println("0 removed");
                       }
                       else
                       {
                               System.out.println("0 not removed");
                       }
               }
               catch(EmptyListException ELE)
               {
                       System.out.println(ELE);
               }

               printLengthAndList(myList);

               int position = myList.findItem(5);
               if(position!=-1)
               {
                       System.out.printf("Value of 5 found at %d ", position);
               }
               else
               {
                       System.out.println("Value of 5 not found");
               }

               position = myList.findItem(2);
               if(position!=-1)
               {
                       System.out.printf("Value of 2 found at %d ", position);
               }
               else
               {
                       System.out.println("Value of 2 not found");
               }

               System.out.printf("Value at position %d being removed ", position);
               myList.removeItem(position);
               printLengthAndList(myList);

               System.out.println("Removing element 0");
               myList.removeItem(0);
               printLengthAndList(myList);

               System.out.println("Removing from front");
               myList.removeFromFront();
               printLengthAndList(myList);

               System.out.println("Getting value at position 2");
               Integer temp = myList.getItem(2);
               System.out.printf("Value at postion is %d ", temp);

               System.out.println("Setting position 0 and 3 to 5");
               myList.setItem(0, 5);
               myList.setItem(3, 5);
               printLengthAndList(myList);

               System.out.println("Testing IndexOutOfBoundsException");/////////////////////////////////////////
               try
               {
                       myList.getItem(4);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }

               try
               {
                       myList.getItem(-1);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }


               try
               {
                       myList.removeItem(4);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }

               try
               {
                       myList.removeItem(-1);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }

               try
               {
                       myList.setItem(-1, 5);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }

               try
               {
                       myList.setItem(4, 5);
               }
               catch(IndexOutOfBoundsException IOBE)
               {
                       System.out.println(IOBE);
               }

               System.out.println("End of IOBE test");

               System.out.println("Clearing if not empty");

               if(!myList.isEmpty())
               {
                       myList.clear();
               }

               printLengthAndList(myList);

               System.out.println("Testing EmptyListException");

               try
               {
                       myList.removeFromFront();
               }
               catch(EmptyListException ELE)
               {
                       System.out.println(ELE);
               }

               try
               {
                       myList.removeFromBack();
               }
               catch(EmptyListException ELE)
               {
                       System.out.println(ELE);
               }

               try
               {
                       myList.sort();
               }
               catch(EmptyListException ELE)
               {
                       System.out.println(ELE);
               }

               System.out.println("End of EmptyListException test");
       }

       public static void printLengthAndList(LinkedList<Integer> l)
       {
               System.out.printf("Length is: %d ", l.lengthIs());
               System.out.println(l);
  
       }

}

LinkedList.java

import dataStructures.ListNode;
import exceptions.EmptyListException;

public class LinkedList<E extends Comparable<E>>
{
    private ListNode<E> firstNode;
    private ListNode<E> lastNode;
    private int numElements;
    private String name;

    public LinkedList()
    {
        name = "Linked List";
        numElements = 0;
        firstNode = null;
        lastNode = null;
    }

    public LinkedList (String name)
    {
        numElements = 0;
        firstNode = null;
        lastNode = null;
    }

    public void insertAtFront (E item)
    {
        if (isEmpty())
        {
            firstNode = lastNode = new ListNode<E> (item);
        }

        else
        {
            ListNode<E> x = new ListNode<E> (item, firstNode);
            firstNode = x;
        }

        numElements++;
    }
    public void insertAtBack (E item)
    {
        if (isEmpty())
        {
            firstNode = lastNode = new ListNode<E> (item);
        }

        else
        {
            ListNode<E> x = new ListNode<E> (item);
            lastNode.setNext(x);
            lastNode = x;
        }

        numElements++;
    }
    public E removeFromFront() throws EmptyListException
    {
        E item = null;

        if (isEmpty())
        {
            throw new EmptyListException (name);
        }

        else if (firstNode == lastNode)
        {
            item = firstNode.getData();
            firstNode = null;
            lastNode = null;

            numElements--;

            return item;
        }

        else
        {
            item = firstNode.getData();
            firstNode = firstNode.getNext();

            numElements--;

            return item;
        }
    }
    public E removeFromBack() throws EmptyListException
    {
        E item = null;

        if (isEmpty())
        {
            throw new EmptyListException(name);
        }

        else if (firstNode == lastNode)
        {
            item = lastNode.getData();
            firstNode = null;
            lastNode = null;

            numElements--;

            return item;
        }

        else
        {
            item = lastNode.getData();

            ListNode<E> ln = firstNode;

            for (int x = 0; x < lengthIs(); x++)
            {
                if (x == (lengthIs() -2))
                {
                    item = ln.getData();
                    lastNode = ln;
                    ln.setNext (null);
                }

                else
                {
                    ln = ln.getNext();
                }
            }

            numElements--;

            return item;
        }
    }
    public void removeItem (int index) throws EmptyListException,IndexOutOfBoundsException
    {
        if (isEmpty())
        {
            throw new EmptyListException (name);
        }

        else
        {
            ListNode<E> x = firstNode;

            if ((index < 0) || (index > (lengthIs() -1)))
            {
                throw new IndexOutOfBoundsException();
            }

            else if (index == 0)
            {
                removeFromBack();
            }

            else
            {
                for (int q = 0; q <= index; q++)
                {
                    if (q == index - 1)
                    {
                        x.setNext (x.getNext().getNext());
                        break;
                    }

                    else
                    {
                        x = x.getNext();
                    }
                }

                numElements--;
            }
        }
    }
    public E getItem (int index) throws EmptyListException, IndexOutOfBoundsException
    {
        E data = null;

        ListNode<E> ln = firstNode;

        if (isEmpty())
        {
            throw new EmptyListException (name);
        }

        else
        {
            if ((index < 0) || (index > (lengthIs() -1)))
            {
                throw new IndexOutOfBoundsException();
            }

            else if (index == lengthIs() -1)
            {
                data = lastNode.getData();
            }

            else if (index == 0)
            {
                data = firstNode.getData();
            }

            else
            {
                for (int x = 0; x <= index; x++)
                {

                    if (x == index)
                    {
                        data = ln.getData();
                        break;
                    }

                    else
                    {
                        ln = ln.getNext();
                    }
                }
            }
        }

        return data;
    }

    public void setItem(int index, E item) throws IndexOutOfBoundsException
    {
        if ((index < 0) || (index > (lengthIs() -1)))
        {
            throw new IndexOutOfBoundsException();
        }


        if (index > 0)
        {
            ListNode<E> node = firstNode;
            for (int x = 1; x < index; x++)
            {
                node = node.getNext();
            }
            node.setData(item);
        }
    }

    public boolean findAndRemove (E item) throws EmptyListException
    {
        if (isEmpty())
        {
            throw new EmptyListException (name);
        }

        else
        {

            if (findItem (item) == -1)
            {
                return false;
            }

            else
            {
                removeItem(findItem(item));

                return true;
            }
        }
    }
    public int findItem (E item)
    {
        int ind = -1;

        ListNode<E> ln = firstNode;

        for (int x = 0; x < lengthIs(); x++)
        {

            if (ln.getData() == item)
            {
                ind = x;
                break;
            }

            else
            {
                ln = ln.getNext();
            }
        }

        return ind;
    }
    public int lengthIs()
    {
        return numElements;
    }

    public void clear()
    {
        numElements = 0;
        firstNode = null;
        lastNode = null;
    }

    // Description: prints list
    public String toString()
    {

        ListNode<E> x = firstNode;
        String n;

        if (numElements == 0)
        {
            n = "";
            return n;
        }

        else
            n = " " + x.getData() + " ";
        if (numElements == 1)
        {
            return n;
        }

        if (isEmpty())
        {
            System.out.println ("Empty" + name);
        }

        else
        {

            System.out.print ("The list " + name + "is: ");

            for (int t = 0; t < lengthIs(); t++)
            {
                x = x.getNext();
                if (x == null)
                {
                    return n;
                }
                n = n + " " + x.getData() + " ";
            }
        }
        return n;
    }

    public void sort() throws EmptyListException
    {

        if (isEmpty())
        {
            throw new EmptyListException (name);
        }

        ListNode<E> a;
        ListNode<E> beforeA = firstNode;
        ListNode<E> b;
        ListNode<E> beforeMin = null;
        ListNode<E> min;
        ListNode<E> temp = null;
        for (a = firstNode; a != null; a = a.getNext())
        {
            min = a;

            for (b = a; b != null; b = b.getNext())
            {
                // beforeMin = beforeA;
                if ((Integer)min.getData() > (Integer)b.getData())
                {
                    min = b;
                }

            }


            temp = new ListNode<E>(a.getData());
            a.setData(min.getData());
            min.setData(temp.getData());
        }
    }
    public boolean isEmpty()
    {

        if (numElements == 0)
        {
            return true;
        }  

        else
        {
            return false;
        }
    }
}

note: due to limited character i cant able to upload all files