So I need to convert the Date to a string in the DayofBirth JOPtionPane areas that starts on lines 43 . it is originally defined as a date and must remain so. The book I am reading recommended using .toString() well that was useless or I just could not figure it out. so how would I keep the Date as is but just convert it so that I can use it in my JOptionPayne for user input and output?
package payrollsystemtest;
import javax.swing.JOptionPane;
/**
*
*
*/
public class PayrollSystemTest
{
public static void main( String args[] )
{
//create a four element employee array
Employee employees[]=new Employee[4];
String first;
String last;
String ssn;
Date DayofBirth;
String salaryString;
double salary =0;
String wageString;
double wage =0;
String hoursString;
int hours =0;
String salesString;
double sales =0;
String rateString;
double rate =0;
String empTypeString="";
int empType=0;
int count;
for(count=0;count<5;count++)
{
empTypeString=
JOptionPane.showInputDialog(null, "What is your employment status?\n\n 1. Salaried\n2.\nHourly\n3.Commissioned\n4.Base Plus Commissioned", "Employee Type", JOptionPane.QUESTION_MESSAGE);
empType=Integer.parseInt(empTypeString);
switch(empType)
{
case 1:
first=JOptionPane.showInputDialog(null,"What is your first name?","First name",JOptionPane.QUESTION_MESSAGE);
last=JOptionPane.showInputDialog(null,"What is your last name?","last name",JOptionPane.QUESTION_MESSAGE);
ssn= JOptionPane.showInputDialog(null,"What is your social security number?","SSN",JOptionPane.QUESTION_MESSAGE);
DayofBirth.toString() =JOptionPane.showInputDialog(null,"What is your date of birth?","Day of Birth",JOptionPane.QUESTION_MESSAGE);
salaryString=JOptionPane.showInputDialog(null,"What is your weekly pay?","salary",JOptionPane.QUESTION_MESSAGE);
salary=Double.parseDouble(salaryString);
break;
case 2:
first=JOptionPane.showInputDialog(null,"What is your first name?","First name",JOptionPane.QUESTION_MESSAGE);
last=JOptionPane.showInputDialog(null,"What is your last name?","last name",JOptionPane.QUESTION_MESSAGE);
ssn= JOptionPane.showInputDialog(null,"What is your social security number?","SSN",JOptionPane.QUESTION_MESSAGE);
DayofBirth =JOptionPane.showInputDialog(null,"What is your date of birth?","Day of Birth",JOptionPane.QUESTION_MESSAGE);
wageString=JOptionPane.showInputDialog(null,"What is hourly wage?","Hourly wage",JOptionPane.QUESTION_MESSAGE);
wage=Double.parseDouble(wageString);
hoursString=JOptionPane.showInputDialog(null,"Please enter the hours worked each week?","Hours worked",JOptionPane.QUESTION_MESSAGE);
hours=Integer.parseInt(hoursString);
break;
case 3:
first=JOptionPane.showInputDialog(null,"What is your first name?","First name",JOptionPane.QUESTION_MESSAGE);
last=JOptionPane.showInputDialog(null,"What is your last name?","last name",JOptionPane.QUESTION_MESSAGE);
ssn= JOptionPane.showInputDialog(null,"What is your social security number?","SSN",JOptionPane.QUESTION_MESSAGE);
DayofBirth =JOptionPane.showInputDialog(null,"What is your date of birth?","Day of Birth",JOptionPane.QUESTION_MESSAGE);
salesString=JOptionPane.showInputDialog(null,"What is your weekly sales?"," sales",JOptionPane.QUESTION_MESSAGE);
sales=Double.parseDouble(salesString);
rateString=JOptionPane.showInputDialog(null,"What is commission rate on your sales?","Commission Rate ",JOptionPane.QUESTION_MESSAGE);
rate=Double.parseDouble(rateString);
break;
case 4:
first=JOptionPane.showInputDialog(null,"What is your first name?","First name",JOptionPane.QUESTION_MESSAGE);
last=JOptionPane.showInputDialog(null,"What is your last name?","last name",JOptionPane.QUESTION_MESSAGE);
ssn= JOptionPane.showInputDialog(null,"What is your social security number?","SSN",JOptionPane.QUESTION_MESSAGE);
DayofBirth =JOptionPane.showInputDialog(null,"What is your date of birth?","Day of Birth",JOptionPane.QUESTION_MESSAGE);
salesString=JOptionPane.showInputDialog(null,"What is your weekly sales?"," sales",JOptionPane.QUESTION_MESSAGE);
sales=Double.parseDouble(salesString);
rateString=JOptionPane.showInputDialog(null,"What is commission rate on your sales?","Commission Rate ",JOptionPane.QUESTION_MESSAGE);
rate=Double.parseDouble(rateString);
salaryString=JOptionPane.showInputDialog(null,"What is your weekly pay?","salary",JOptionPane.QUESTION_MESSAGE);
salary=Double.parseDouble(salaryString);
break;
default:
JOptionPane.showMessageDialog(null,"Invalid entry, please try again","Try Again" ,JOptionPane.ERROR_MESSAGE);
break;
}
switch(count)
{
case 0: Employees[0]=new
SalariedEmployee(first,last,ssn,DayofBirth,salary);
break;
case 1: Employees[1]=new
HourlyEmployee(first,last,ssn,DayofBirth,wage,hours);
break;
case 2: Employees[2]=new
CommissionEmployee(first,last,ssn,DayofBirth,sales,rate);
break;
case 3: Employee[3]=new
BasePlusCommissionemployee(first,last,ssn,DayofBirth,sales,rate,salary);
}
}
for ( Employee currentEmployee : employees )
{
System.out.println( currentEmployee ); // invokes toString
// determine whether element is a BasePlusCommissionEmployee
if ( currentEmployee instanceof BasePlusCommissionEmployee )
{
// downcast Employee reference to
// BasePlusCommissionEmployee reference
BasePlusCommissionEmployee employee =
( BasePlusCommissionEmployee ) currentEmployee;
double oldBaseSalary = employee.getBaseSalary();
employee.setBaseSalary( 1.10 * oldBaseSalary );
System.out.printf(
"new base salary with 10%% increase is: $%,.2f\n",
employee.getBaseSalary() );
} // end if
if(currentDate.getMonth()==currentEmployee.getBirthday().getMonth())
{
System.out.printf("earned $%,.2f. %s\n\n", currentEmployee.earnings() + 100.00,
"Note: added a $100 bonus to your payroll amount for birthday!!!" );
}else{
System.out.printf("earned $%,.2f\n\n", currentEmployee.earnings() );
}
} // end for
// get type name of each object in employees array
for ( int j = 0; j < employees.length; j++ )
System.out.printf( "Employee %d is a %s\n", j,
employees[ j ].getClass().getSimpleName() );
} // end main