I am new to Java and have been working on an Employee/Salary program. The program runs fine, however I would like to clean it up. I was told that I should try to create a relationship with classes utilizing Polymorphism. Unfortunately, I have not been able to grasp the functionality of it. I am pasteing the portion of the program I am trying to cleanup and would welcome any suggestions. I am especially interest in a simplified explaination of polymorphism.<br><br>This program when put together with the other works fine, except it does not display salary and should and I need to clean up from //create boss. <br><br>public abstract class Employee {<br> private String firstName;<br> private String lastName;<br> private Date Birthdate;<br> private int DepartmentCode;<br><br> // Constructor<br> public Employee( String first, String last, int m, int d, int y, int dept )<br><br> {<br> Birthdate = new Date(m,d,y);<br> firstName = first;<br> lastName = last;<br> DepartmentCode = dept;<br> }<br><br> // Return the first name<br> public String getFirstName() { return firstName; }<br><br> // Return the last name<br> public String getLastName() { return lastName; }<br><br> // Return the Birthdate<br> public String toString()<br> { return firstName + ' ' + lastName + ' ' + Birthdate.toString(); }<br><br> public int getBirthmonth()<br> { return Birthdate.getmonth(); }<br><br> // Abstract method that must be implemented for each<br> // derived class of Employee from which objects<br> // are instantiated.<br> public abstract double earnings(); <br>}<br><br>import javax.swing.JOptionPane;<br>import java.text.DecimalFormat;<br>import java.io.*;<br>import javax.swing.*;<br><br>public class ReadEmployee {<br><br>private ObjectInputStream input;<br><br> private void openFile()<br> {<br> JFileChooser fileChooser = new JFileChooser();<br> fileChooser.setFileSelectionMode(<br> JFileChooser.FILES_ONLY );<br><br> int result = fileChooser.showSaveDialog( null );<br><br> // user clicked Cancel button on dialog<br> if ( result == JFileChooser.CANCEL_OPTION )<br> return;<br><br> File fileName = fileChooser.getSelectedFile();<br><br> if ( fileName == null ¦¦<br> fileName.getName().equals( "" ) )<br> JOptionPane.showMessageDialog( null,<br> "Invalid File Name",<br> "Invalid File Name",<br> JOptionPane.ERROR_MESSAGE );<br> else {<br> // Open the file<br> try {<br> input = new ObjectInputStream(<br> new FileInputStream( fileName ) );<br> }<br> catch ( IOException e ) {<br> JOptionPane.showMessageDialog( null,<br> "Error Opening File", "Error",<br> JOptionPane.ERROR_MESSAGE );<br> }<br> }<br> }<br><br> private void closeFile()<br> {<br> try {<br> input.close();<br> }<br> catch( IOException ex ) {<br> JOptionPane.showMessageDialog( null,<br> "Error closing file",<br> "Error", JOptionPane.ERROR_MESSAGE );<br> System.exit( 1 );<br> }<br> }<br><br> public Employee readRecord()<br> {<br><br> Employee inputEmployee;<br><br> inputEmployee = null;<br><br> // input the values from the file<br> try {<br> inputEmployee = (Employee) input.readObject();<br><br> }<br> catch ( EOFException eofex ) {<br> JOptionPane.showMessageDialog( null,<br> "No more records in file",<br> "End of File", JOptionPane.ERROR_MESSAGE );<br> }<br> catch ( ClassNotFoundException cnfex ) {<br> JOptionPane.showMessageDialog( null,<br> "Unable to create object",<br> "Class Not Found", JOptionPane.ERROR_MESSAGE );<br> }<br> catch ( IOException ioex ) {<br> JOptionPane.showMessageDialog( null,<br> "Error during read from file",<br> "Read Error", JOptionPane.ERROR_MESSAGE );<br> }<br><br> return inputEmployee;<br> }<br><br> public ReadEmployee()<br> {<br> int thisMonth = 11; // what month is it now<br> int i; // loop counter<br> Employee ref; // superclass reference<br> String output = ""; // container for message<br> Employee arrayOfEmployees[]; // define array for objects<br> arrayOfEmployees = new Employee[4]; // initialize array of objects<br><br> openFile();<br><br> //create a boss<br> ref = readRecord();<br> Boss b = new Boss( ref.getLastName(), ref.getFirstName(), 0,<br> ref.getbirthMonth(), ref.getbirthDay(), ref.getbirthYear(),<br> ref.getDepartmentCode());<br><br> //put object in array<br> arrayOfEmployees[0] = b;<br><br> //create a commission worker<br> ref = readRecord();<br> CommissionWorker c =<br> new CommissionWorker( ref.getLastName(), ref.getFirstName(), 0, 0, 0,<br> ref.getbirthMonth(), ref.getbirthDay(), ref.getbirthYear(),<br> ref.getDepartmentCode());<br><br> //put object in array<br> arrayOfEmployees[1] = c;<br><br> //create a piece worker<br> ref = readRecord();<br> PieceWorker p =<br> new PieceWorker( ref.getLastName(), ref.getFirstName(), 0, 0,<br> ref.getbirthMonth(), ref.getbirthDay(), ref.getbirthYear(),<br> ref.getDepartmentCode());<br><br> //put object in array<br> arrayOfEmployees[2] = p;<br><br> //create an hourly worker<br> ref = readRecord();<br> HourlyWorker h =<br> new HourlyWorker( ref.getLastName(), ref.getFirstName(), 0, 0,<br> ref.getbirthMonth(), ref.getbirthDay(), ref.getbirthYear(),<br> ref.getDepartmentCode());<br><br> //put object in array<br> arrayOfEmployees[3] = h;<br><br> //create object to format earnings<br> DecimalFormat precision2 = new DecimalFormat( "0.00" );<br><br> output += "This month is " + thisMonth + "\n";<br><br> // loop over array building output for each employee<br> for ( i = 0; i < arrayOfEmployees.length; i++ ) {<br><br> //get one employee from the array<br> ref = arrayOfEmployees[ i ];<br><br> //ask the employee for their information<br> output += ref.toString() + " earned $" + "\n " +<br> precision2.format( ref.earnings() ) + "\n" ;<br><br> //ask the employee for their birth month<br> if (ref.getbirthMonth() == thisMonth) {<br> output += " Happy Birthday Bonus: $100 \n"; }<br><br> } // for<br><br> closeFile();<br><br> //display results<br> JOptionPane.showMessageDialog( null, output,<br> "Demonstrating Polymorphism",<br> JOptionPane.INFORMATION_MESSAGE );<br> System.exit( 0 );<br> }<br><br> public static void main( String args[] )<br> {<br><br> new ReadEmployee();<br><br> }<br><br>}<br><br><br><br><br><br>