import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class PayrollSystemTest {
public static void main( String[] args )
{
String workerType;
String first;
String last;
String ssn;
int month;
int day;
int year;
float salary;
float rate;
float hourlyWage=0;
float hours;
float wage;
float sales;
DecimalFormat twoDigits = new DecimalFormat( "0.00" );
// create Employee array
Employee employees[] = new Employee[ 5 ];
// generically process each element in array employees
for ( int empNo = 1; empNo <=5; empNo++ ) {
workerType=JOptionPane.showInputDialog(
"Please enter the type of worker:\n\n" +
"Salaried\nHourly\nCommission\n" +
"Base Plus Commission\nQuit, To Quit");
if(workerType.equalsIgnoreCase("Salaried")){
first=JOptionPane.showInputDialog("Enter employee " + empNo +
" first name: ");
last=JOptionPane.showInputDialog("Enter employee " + empNo +
" last name: ");
ssn=JOptionPane.showInputDialog(
"Enter employee " + empNo + " ssn: ");
month=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth month(1-12): "));
day=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth day(1-31): "));
year=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth year(yyyy): "));
salary=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " weekly salary: "));
employees[empNo-1] = new SalariedEmployee(first, last,
ssn, month, day, year, salary);
}
else if(workerType.equalsIgnoreCase("Hourly")){
first=JOptionPane.showInputDialog("Enter employee " + empNo +
" first name: ");
last=JOptionPane.showInputDialog("Enter employee " + empNo +
" last name: ");
ssn=JOptionPane.showInputDialog(
"Enter employee " + empNo + " ssn: ");
month=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth month(1-12): "));
day=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth day(1-31): "));
year=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth year(yyyy): "));
hourlyWage=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " hourly wage: "));
hours=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " hours worked: "));
employees[empNo-1] = new HourlyEmployee(first, last, ssn,
month, day, year, hourlyWage, hours);
}
else if(workerType.equalsIgnoreCase("Commission")){
first=JOptionPane.showInputDialog("Enter employee " + empNo +
" first name: ");
last=JOptionPane.showInputDialog("Enter employee " + empNo +
" last name: ");
ssn=JOptionPane.showInputDialog(
"Enter employee " + empNo + " ssn: ");
month=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth month(1-12): "));
day=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth day(1-31): "));
year=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth year(yyyy): "));
sales=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " weekly sales: "));
rate=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " commission rate: "));
employees[empNo-1] = new CommissionEmployee(first, last,
ssn, month, day, year, sales, rate);
}
else if(workerType.equalsIgnoreCase("Base Plus Commission")){
first=JOptionPane.showInputDialog("Enter employee " + empNo +
" first name: ");
last=JOptionPane.showInputDialog("Enter employee " + empNo +
" last name: ");
ssn=JOptionPane.showInputDialog(
"Enter employee " + empNo + " ssn: ");
month=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth month(1-12): "));
day=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth day(1-31): "));
year=Integer.parseInt(JOptionPane.showInputDialog(
"Enter employee " + empNo + " birth year(yyyy): "));
sales=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " weekly sales: "));
rate=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " commission rate: "));
salary=Float.parseFloat(JOptionPane.showInputDialog(
"Enter employee " + empNo + " base salary: "));
employees[2] =
new BasePlusCommissionEmployee(first, last, ssn, month,
day, year, sales, rate, salary);
}
else if(workerType.equalsIgnoreCase("Quit")){
break;
}
}
// initialize array with Employees
//employees[ 0 ] = new SalariedEmployee( "John", "Smith",
// "111-11-1111", 1000, 1, 1, 1960 );
//employees[ 1 ] = new CommissionEmployee( "Sue", "Jones",
// "222-22-2222", 12000, .05, 2, 1, 1962 );
//employees[ 2 ] = new BasePlusCommissionEmployee( "Bob", "Lewis",
// "333-33-3333", 10000, .03, 500, 3, 1, 1963 );
//employees[ 3 ] = new HourlyEmployee( "Karen", "Price",
// "444-44-4444", 20., 40, 4, 1, 1964 );
//employees[ 4 ] = new SalariedEmployee( "Brian", "Dawkins",
// "555-55-5555", 1000, 11, 1, 1961 );
String output ="";
for(int i=1; i<employees.length+1; i++){
[u]output += employees[i-1].toString();[/u][u][b][/b]<<<<<This Line
// determine whether element is a BasePlusCommissionEmployee
if ( employees[ i-1 ] instanceof BasePlusCommissionEmployee ) {
// downcast Employee reference to
// BasePlusCommissionEmployee reference
BasePlusCommissionEmployee currentEmployee =
( BasePlusCommissionEmployee ) employees[ i-1 ];
double oldBaseSalary = currentEmployee.getBaseSalary();
output += "\nold base salary: $" + oldBaseSalary;
currentEmployee.setBaseSalary( 1.10 * oldBaseSalary );
output += "\nnew base salary with 10% increase is: $" +
currentEmployee.getBaseSalary();
} // end if
output += "\nearned $" + employees[ i-1 ].earnings()*4 + "\n";
} // end for
// get type name of each object in employees array
for ( int j = 1; j < employees.length+1; j++ )
[/u][b]<<<<<This line JOptionPane.showMessageDialog( null, output ); // display output
System.exit( 0 );
} // end main
} // end class PayrollSystemTest
I get two gifferent errors