So I need all I need to do is let this info that is going through my array print out somehow. the problem is I cant get it to do that currently. I can get it to return the information one at a time for each employee . but at the end I want it to run through the final loop and print out all the employees in a list for that is stored . The code at the bottom goes with my other super classes and must stay the same , I just need to know how to get it to print out to the screen. I was thinking line 49 I would need a println but I am not sure what I am doing wrong the entire program is working fine with that exception. there are 6 superclass all related to this payrollsystemtest but there are no error related to them.
package test;
import java.util.Scanner;
// test
//
public class Test {
private static final int BONUS_MONTH = 11;
private static int emptype;
private static String first;
private static String last;
private static String ssn;
private static int month;
private static int day;
private static int year;
private static double salary;
private static double sales;
private static double rate;
private static double hourlyWage;
private static double hoursWorked;
private static double grossSales;
private static double commissionRate;
private static double baseSalary;
public static void main(String args[]) {
Employee employees[] = new Employee[5];
// create scanner object to get values from user
int count;
for(count=0;count<5;count++)
{
//menu here
menu();
// initialize array with Employees
employees[0] = new SalariedEmployee(first,last ,ssn , month, day, year, salary );
employees[1] = new SalariedEmployee(first,last ,ssn , month, day, year, salary );
employees[2] = new HourlyEmployee( first, last, ssn, month, day, year , hourlyWage, hoursWorked );
employees[3] = new CommissionEmployee( first, last, ssn, month, day, year, sales, rate );
employees[4] = new BasePlusCommissionEmployee( first, last, ssn, month, day, year, sales, rate, salary );
}
System.out.println("Employees processed polymorphically:\n");
// generically process each element in array employees
double earnings = 0;
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
// Add $100 bonus if birth month is November while calculating
// monthly salary
if (currentEmployee.getBirthday().getMonth() == BONUS_MONTH) {
earnings = (currentEmployee.earnings() * 4) + 100;
} else {
earnings = currentEmployee.earnings() * 4;
}
// Print monthly salary
System.out.printf("earned $%,.2f\n\n", 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().getName());
} // end main
private static SalariedEmployee salaryString(Scanner input) {
System.out.println("Please enter first name.");
first = input.next();
System.out.println("Please enter last name.");
last = input.next();
System.out.println("Please enter SSN.");
ssn = input.next();
System.out.println("Please enter Month of Birth.");
month = input.nextInt();
System.out.println("Please enter Day of Birth.");
day = input.nextInt();
System.out.println("Please enter Year of Birth.");
year = input.nextInt();
System.out.println("Please enter Salary.");
salary = input.nextDouble();
// create subclass objects
SalariedEmployee salariedEmployee = new SalariedEmployee(first, last, ssn, month, day, year, salary);
return salariedEmployee;
}
private static HourlyEmployee HourString(Scanner input) {
System.out.println("\nHourly Employee Details");
System.out.println("Please enter first name.");
first = input.next();
System.out.println("Please enter last name.");
last = input.next();
System.out.println("Please enter SSN.");
ssn = input.next();
System.out.println("Please enter Month of Birth.");
month = input.nextInt();
System.out.println("Please enter Day of Birth.");
day = input.nextInt();
System.out.println("Please enter Year of Birth.");
year = input.nextInt();
System.out.println("Please enter hourly wages.");
hourlyWage = input.nextDouble();
System.out.println("Please enter hours worked.");
hoursWorked = input.nextDouble();
HourlyEmployee hourlyEmployee = new HourlyEmployee(first, last, ssn, month, day, year, hourlyWage,
hoursWorked);
return hourlyEmployee;
}
private static CommissionEmployee RateString(Scanner input) {
System.out.println("\nCommission Employee Details");
System.out.println("Please enter first name.");
first = input.next();
System.out.println("Please enter last name.");
last = input.next();
System.out.println("Please enter SSN.");
ssn = input.next();
System.out.println("Please enter Month of Birth.");
month = input.nextInt();
System.out.println("Please enter Day of Birth.");
day = input.nextInt();
System.out.println("Please enter Year of Birth.");
year = input.nextInt();
System.out.println("Please enter gross sales.");
grossSales = input.nextDouble();
System.out.println("Please enter commission rate.");
commissionRate = input.nextDouble();
CommissionEmployee commissionEmployee = new CommissionEmployee(first, last, ssn, month, day, year,
grossSales, commissionRate);
return commissionEmployee;
}
private static BasePlusCommissionEmployee SalesString(Scanner input) {
System.out.println("\nBase Plus Commission Employee Details");
System.out.println("Please enter first name.");
first = input.next();
System.out.println("Please enter last name.");
last = input.next();
System.out.println("Please enter SSN.");
ssn = input.next();
System.out.println("Please enter Month of Birth.");
month = input.nextInt();
System.out.println("Please enter Day of Birth.");
day = input.nextInt();
System.out.println("Please enter Year of Birth.");
year = input.nextInt();
System.out.println("Please enter gross sales.");
grossSales = input.nextDouble();
System.out.println("Please enter commission rate.");
commissionRate = input.nextDouble();
System.out.println("Please enter base salary.");
baseSalary = input.nextDouble();
BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(first, last,
ssn, month, day, year, grossSales, commissionRate, baseSalary);
return basePlusCommissionEmployee;
}
/**
*
*/
public static void menu()
{
Scanner input = new Scanner(System.in);
System.out.println("\nPlease Select an Emploment Type or -1 to quit:\n");
System.out.println("\n 1. Salaried Employee");
System.out.println("\n 2. Commissioned Employee");
System.out.println("\n 3. Base Plus Commissioned Employee");
System.out.println("\n 4. Hourly employee");
emptype = input.nextInt();
input.nextLine();
switch(emptype)
{
case 1:
SalariedEmployee salariedEmployee = salaryString(input);
break;
case 2:
CommissionEmployee commissionEmployee = RateString(input);
break;
case 3:
BasePlusCommissionEmployee basePlusCommissionEmployee = SalesString(input);
break;
case 4:
HourlyEmployee hourlyEmployee = HourString(input);
break;
default:
System.out.println("\n incorrect choice Please try again");
break;
}
}
} // end class PayrollSystemTest