Results 1 to 7 of 7
  1. #1
    khollinghead is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Java Application-Employee Payroll System error PayrollSystemTest.java:56: error: ')'

    Problem with program getting error-this is homework and I can get all files to compile except the final one. Any help is appreciated.


    import java.util.Scanner;

    // PayrollSystemTest.java
    // Employee hierarchy test program.

    public class PayrollSystemTest {
    private static final int BONUS_MONTH = 11;

    public static void main(String args[]) {
    // create scanner object to get values from user
    Scanner input = new Scanner(System.in);

    System.out.println("Employees process polymorphically:\n");

    SalariedEmployee salariedEmployee = getSalariedEmployeeObject(input);
    HourlyEmployee hourlyEmployee = getHourlyEmployeeObject(input);
    CommissionEmployee commissionEmployee = getCommissionEmployeeObject(input);
    BasePlusCommissionEmployee basePlusCommissionEmployee = getBasePlusCommissionEmployeeObject(input);

    System.out.println("Employees processed individually:\n");

    System.out.printf("%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", hourlyEmployee, "earned", hourlyEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", commissionEmployee, "earned", commissionEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned",
    basePlusCommissionEmployee.earnings());

    // create four-element Employee array
    Employee employees[] = new Employee[4];

    // initialize array with Employees
    employees[0] = salariedEmployee;
    employees[1] = hourlyEmployee;
    employees[2] = commissionEmployee;
    employees[3] = basePlusCommissionEmployee;

    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.getBirthDate().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 getSalariedEmployeeObject(Scanner input) {
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter Salary.");
    double salary = input.nextDouble();
    // create subclass objects
    SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, month, day, year, salary);
    return salariedEmployee;
    }

    private static HourlyEmployee getHourlyEmployeeObject(Scanner input) {
    System.out.println("\nHourly Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter hourly wages.");
    double hourlyWages = input.nextDouble();
    System.out.println("Please enter hours worked.");
    double hoursWorked = input.nextDouble();
    HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, month, day, year, hourlyWages,
    hoursWorked);
    return hourlyEmployee;
    }

    private static CommissionEmployee getCommissionEmployeeObject(Scanner input) {
    System.out.println("\nCommission Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter gross sales.");
    double grossSales = input.nextDouble();
    System.out.println("Please enter commission rate.");
    double commissionRate = input.nextDouble();
    CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, month, day, year,
    grossSales, commissionRate);
    return commissionEmployee;
    }

    private static BasePlusCommissionEmployee getBasePlusCommissionEmployeeObject(Scanner input) {
    System.out.println("\nBase Plus Commission Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter gross sales.");
    double grossSales = input.nextDouble();
    System.out.println("Please enter commission rate.");
    double commissionRate = input.nextDouble();
    System.out.println("Please enter base salary.");
    double baseSalary = input.nextDouble();
    BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    ssn, month, day, year, grossSales, commissionRate, baseSalary);
    return basePlusCommissionEmployee;
    }
    } // end class PayrollSystemTest

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    Quote Originally Posted by khollinghead View Post
    Problem with program getting error-this is homework and I can get all files to compile except the final one. Any help is appreciated.
    When posting code in the forum, please use code tags around well formatted code to allow us to be able to better be able to read and understand your code. The tag [code] goes above your posted code block, and the tag [/code] goes below it.

    Your question heading states, "Java Application-Employee Payroll System error PayrollSystemTest.java:56: error: ')'"

    Can you post your complete error message, and can you indicate to us in some way exactly which line is the one the message is talking about, line 56?

    Note, your code with code tags added:
    Java Code:
    import java.util.Scanner;
    
    // PayrollSystemTest.java
    // Employee hierarchy test program.
    
    public class PayrollSystemTest {
    	private static final int BONUS_MONTH = 11;
    
    	public static void main(String args[]) {
    		// create scanner object to get values from user
    		Scanner input = new Scanner(System.in);
    
    		System.out.println("Employees process polymorphically:\n");
    
    		SalariedEmployee salariedEmployee = getSalariedEmployeeObject(input);
    		HourlyEmployee hourlyEmployee = getHourlyEmployeeObject(input);
    		CommissionEmployee commissionEmployee = getCommissionEmployeeObject(input);
    		BasePlusCommissionEmployee basePlusCommissionEmployee = getBasePlusCommissionEmployeeObject(input);
    
    		System.out.println("Employees processed individually:\n");
    
    		System.out.printf("%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", hourlyEmployee, "earned", hourlyEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", commissionEmployee, "earned", commissionEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned",
    				basePlusCommissionEmployee.earnings());
    
    		// create four-element Employee array
    		Employee employees[] = new Employee[4];
    
    		// initialize array with Employees
    		employees[0] = salariedEmployee;
    		employees[1] = hourlyEmployee;
    		employees[2] = commissionEmployee;
    		employees[3] = basePlusCommissionEmployee;
    
    		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.getBirthDate().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 getSalariedEmployeeObject(Scanner input) {
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter Salary.");
    		double salary = input.nextDouble();
    		// create subclass objects
    		SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, month, day, year, salary);
    		return salariedEmployee;
    	}
    
    	private static HourlyEmployee getHourlyEmployeeObject(Scanner input) {
    		System.out.println("\nHourly Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter hourly wages.");
    		double hourlyWages = input.nextDouble();
    		System.out.println("Please enter hours worked.");
    		double hoursWorked = input.nextDouble();
    		HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, month, day, year, hourlyWages,
    				hoursWorked);
    		return hourlyEmployee;
    	}
    
    	private static CommissionEmployee getCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nCommission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, month, day, year,
    				grossSales, commissionRate);
    		return commissionEmployee;
    	}
    
    	private static BasePlusCommissionEmployee getBasePlusCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nBase Plus Commission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		System.out.println("Please enter base salary.");
    		double baseSalary = input.nextDouble();
    		BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    				ssn, month, day, year, grossSales, commissionRate, baseSalary);
    		return basePlusCommissionEmployee;
    	}
    } // end class PayrollSystemTest

  3. #3
    khollinghead is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    Thanks for the reply. I'm new to the forum and have reached the end.
    I have a few .java files. Employee, Date, CommissionEmployee, BasePlusCommission, HourlyEmployee, SalariedEmployee and then PayrollSystemTest.
    All files compile except the PayrollSystemTest.

    Error Code is

    PayrollSystemTest.java:56: error: cannot find symbol
    if (currentEmployee.getBirthDate().getMonth() == BONUS_MONTH) {
    ^
    symbol: method getMonth()
    location: class String
    PayrollSystemTest.java:86: error: constructor SalariedEmployee in class SalariedEmployee cannot be applied to given types;
    SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, month, day, year, salary);
    ^
    required: String,String,String,double,String,int
    found: String,String,String,int,int,int,double
    reason: actual and formal argument lists differ in length
    PayrollSystemTest.java:108: error: constructor HourlyEmployee in class HourlyEmployee cannot be applied to given types;
    HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, month, day, year, hourlyWages,
    ^
    required: String,String,String,double,double,String,int
    found: String,String,String,int,int,int,double,double
    reason: actual and formal argument lists differ in length
    PayrollSystemTest.java:131: error: constructor CommissionEmployee in class CommissionEmployee cannot be applied to given types;
    CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, month, day, year,
    ^
    required: String,String,String,double,double,String,int
    found: String,String,String,int,int,int,double,double
    reason: actual and formal argument lists differ in length
    PayrollSystemTest.java:156: error: constructor BasePlusCommissionEmployee in class BasePlusCommissionEmployee cannot be applied to given types;
    BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    ^
    required: String,String,String,double,double,double,String,i nt
    found: String,String,String,int,int,int,double,double,dou ble
    reason: actual and formal argument lists differ in length
    5 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    Code follows. Hope this is correct.


    Error code is



    [import java.util.Scanner;

    // PayrollSystemTest.java
    // Employee hierarchy test program.

    public class PayrollSystemTest {
    private static final int BONUS_MONTH = 11;

    public static void main(String args[]) {
    // create scanner object to get values from user
    Scanner input = new Scanner(System.in);

    System.out.println("Employees process polymorphically:\n");

    SalariedEmployee salariedEmployee = getSalariedEmployeeObject(input);
    HourlyEmployee hourlyEmployee = getHourlyEmployeeObject(input);
    CommissionEmployee commissionEmployee = getCommissionEmployeeObject(input);
    BasePlusCommissionEmployee basePlusCommissionEmployee = getBasePlusCommissionEmployeeObject(input);

    System.out.println("Employees processed individually:\n");

    System.out.printf("%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", hourlyEmployee, "earned", hourlyEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", commissionEmployee, "earned", commissionEmployee.earnings());
    System.out.printf("%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned",
    basePlusCommissionEmployee.earnings());

    // create four-element Employee array
    Employee employees[] = new Employee[4];

    // initialize array with Employees
    employees[0] = salariedEmployee;
    employees[1] = hourlyEmployee;
    employees[2] = commissionEmployee;
    employees[3] = basePlusCommissionEmployee;

    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.getBirthDate().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 getSalariedEmployeeObject(Scanner input) {
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter Salary.");
    double salary = input.nextDouble();
    // create subclass objects
    SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, month, day, year, salary);
    return salariedEmployee;
    }

    private static HourlyEmployee getHourlyEmployeeObject(Scanner input) {
    System.out.println("\nHourly Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter hourly wages.");
    double hourlyWages = input.nextDouble();
    System.out.println("Please enter hours worked.");
    double hoursWorked = input.nextDouble();
    HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, month, day, year, hourlyWages,
    hoursWorked);
    return hourlyEmployee;
    }

    private static CommissionEmployee getCommissionEmployeeObject(Scanner input) {
    System.out.println("\nCommission Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter gross sales.");
    double grossSales = input.nextDouble();
    System.out.println("Please enter commission rate.");
    double commissionRate = input.nextDouble();
    CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, month, day, year,
    grossSales, commissionRate);
    return commissionEmployee;
    }

    private static BasePlusCommissionEmployee getBasePlusCommissionEmployeeObject(Scanner input) {
    System.out.println("\nBase Plus Commission Employee Details");
    System.out.println("Please enter first name.");
    String firstName = input.next();
    System.out.println("Please enter last name.");
    String lastName = input.next();
    System.out.println("Please enter SSN.");
    String ssn = input.next();
    System.out.println("Please enter Month of Birth.");
    int month = input.nextInt();
    System.out.println("Please enter Day of Birth.");
    int day = input.nextInt();
    System.out.println("Please enter Year of Birth.");
    int year = input.nextInt();
    System.out.println("Please enter gross sales.");
    double grossSales = input.nextDouble();
    System.out.println("Please enter commission rate.");
    double commissionRate = input.nextDouble();
    System.out.println("Please enter base salary.");
    double baseSalary = input.nextDouble();
    BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    ssn, month, day, year, grossSales, commissionRate, baseSalary);
    return basePlusCommissionEmployee;
    }
    } // end class PayrollSystemTest
    ]

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    Please re-read about code tags. Please edit your post above so that it's readable. If you go into advanced editing you can see what your post will look like before you post it.

  5. #5
    khollinghead is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    Sorry. Not paying attention and worried about finishing this.
    Java Code:
    import java.util.Scanner;
    
    // PayrollSystemTest.java
    // Employee hierarchy test program.
    
    public class PayrollSystemTest {
    	private static final int BONUS_MONTH = 11;
    
    	public static void main(String args[]) {
    		// create scanner object to get values from user
    		Scanner input = new Scanner(System.in);
    
    		System.out.println("Employees process polymorphically:\n");
    
    		SalariedEmployee salariedEmployee = getSalariedEmployeeObject(input);
    		HourlyEmployee hourlyEmployee = getHourlyEmployeeObject(input);
    		CommissionEmployee commissionEmployee = getCommissionEmployeeObject(input);
    		BasePlusCommissionEmployee basePlusCommissionEmployee = getBasePlusCommissionEmployeeObject(input);
    
    		System.out.println("Employees processed individually:\n");
    
    		System.out.printf("%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", hourlyEmployee, "earned", hourlyEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", commissionEmployee, "earned", commissionEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned",
    				basePlusCommissionEmployee.earnings());
    
    		// create four-element Employee array
    		Employee employees[] = new Employee[4];
    
    		// initialize array with Employees
    		employees[0] = salariedEmployee;
    		employees[1] = hourlyEmployee;
    		employees[2] = commissionEmployee;
    		employees[3] = basePlusCommissionEmployee;
    
    		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.getBirthDate().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 getSalariedEmployeeObject(Scanner input) {
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter Salary.");
    		double salary = input.nextDouble();
    		// create subclass objects
    		SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, month, day, year, salary);
    		return salariedEmployee;
    	}
    
    	private static HourlyEmployee getHourlyEmployeeObject(Scanner input) {
    		System.out.println("\nHourly Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter hourly wages.");
    		double hourlyWages = input.nextDouble();
    		System.out.println("Please enter hours worked.");
    		double hoursWorked = input.nextDouble();
    		HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, month, day, year, hourlyWages,
    				hoursWorked);
    		return hourlyEmployee;
    	}
    
    	private static CommissionEmployee getCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nCommission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, month, day, year,
    				grossSales, commissionRate);
    		return commissionEmployee;
    	}
    
    	private static BasePlusCommissionEmployee getBasePlusCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nBase Plus Commission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Day of Birth.");
    		int day = input.nextInt();
    		System.out.println("Please enter Year of Birth.");
    		int year = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		System.out.println("Please enter base salary.");
    		double baseSalary = input.nextDouble();
    		BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    				ssn, month, day, year, grossSales, commissionRate, baseSalary);
    		return basePlusCommissionEmployee;
    	}
    } // end class PayrollSystemTest

  6. #6
    khollinghead is offline Member
    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    ok I've corrected a view things. Here's the new code.
    Java Code:
    import java.util.Scanner;
    
    // PayrollSystemTest.java
    // Employee hierarchy test program.
    
    public class PayrollSystemTest {
    	private static final int BONUS_MONTH = 11;
    
    	public static void main(String args[]) {
    		// create scanner object to get values from user
    		Scanner input = new Scanner(System.in);
    
    		System.out.println("Employees process polymorphically:\n");
    
    		SalariedEmployee salariedEmployee = getSalariedEmployeeObject(input);
    		HourlyEmployee hourlyEmployee = getHourlyEmployeeObject(input);
    		CommissionEmployee commissionEmployee = getCommissionEmployeeObject(input);
    		BasePlusCommissionEmployee basePlusCommissionEmployee = getBasePlusCommissionEmployeeObject(input);
    
    		System.out.println("Employees processed individually:\n");
    
    		System.out.printf("%s\n%s: $%,.2f\n\n", salariedEmployee, "earned", salariedEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", hourlyEmployee, "earned", hourlyEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", commissionEmployee, "earned", commissionEmployee.earnings());
    		System.out.printf("%s\n%s: $%,.2f\n\n", basePlusCommissionEmployee, "earned",
    				basePlusCommissionEmployee.earnings());
    
    		// create four-element Employee array
    		Employee employees[] = new Employee[4];
    
    		// initialize array with Employees
    		employees[0] = salariedEmployee;
    		employees[1] = hourlyEmployee;
    		employees[2] = commissionEmployee;
    		employees[3] = basePlusCommissionEmployee;
    
    		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.getBirthDate().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 getSalariedEmployeeObject(Scanner input) {
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter Salary.");
    		double salary = input.nextDouble();
    		// create subclass objects
    		SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, birth, month, salary);
    		return salariedEmployee;
    	}
    
    	private static HourlyEmployee getHourlyEmployeeObject(Scanner input) {
    		System.out.println("\nHourly Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter hourly wages.");
    		double hourlyWages = input.nextDouble();
    		System.out.println("Please enter hours worked.");
    		double hoursWorked = input.nextDouble();
    		HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, birth, month, hourlyWages,
    				hoursWorked);
    		return hourlyEmployee;
    	}
    
    	private static CommissionEmployee getCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nCommission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, birth, month, 
          grossSales, commissionRate);
    		return commissionEmployee;
    	}
    
    	private static BasePlusCommissionEmployee getBasePlusCommissionEmployeeObject(Scanner input) {
    		System.out.println("\nBase Plus Commission Employee Details");
    		System.out.println("Please enter first name.");
    		String firstName = input.next();
    		System.out.println("Please enter last name.");
    		String lastName = input.next();
    		System.out.println("Please enter SSN.");
    		String ssn = input.next();
    		System.out.println("Please enter Month of Birth.");
    		int month = input.nextInt();
    		System.out.println("Please enter gross sales.");
    		double grossSales = input.nextDouble();
    		System.out.println("Please enter commission rate.");
    		double commissionRate = input.nextDouble();
    		System.out.println("Please enter base salary.");
    		double baseSalary = input.nextDouble();
    		BasePlusCommissionEmployee basePlusCommissionEmployee = new BasePlusCommissionEmployee(firstName, lastName,
    				ssn, birth, month, grossSales, commissionRate, baseSalary);
    		return basePlusCommissionEmployee;
    	}
    } // end class PayrollSystemTest
    errors are the same though

    Java Code:
     ----jGRASP exec: javac -g PayrollSystemTest.java
    
    PayrollSystemTest.java:56: error: cannot find symbol
    			if (currentEmployee.getBirthDate().getMonth() == BONUS_MONTH) {
    			                                  ^
      symbol:   method getMonth()
      location: class String
    PayrollSystemTest.java:82: error: cannot find symbol
    		SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, birth, month, salary);
    		                                                                                   ^
      symbol:   variable birth
      location: class PayrollSystemTest
    PayrollSystemTest.java:100: error: cannot find symbol
    		HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, birth, month, hourlyWages,
    		                                                                             ^
      symbol:   variable birth
      location: class PayrollSystemTest
    PayrollSystemTest.java:119: error: cannot find symbol
    		CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, birth, month, 
    		                                                                                         ^
      symbol:   variable birth
      location: class PayrollSystemTest
    PayrollSystemTest.java:141: error: cannot find symbol
    				ssn, birth, month, grossSales, commissionRate, baseSalary);
    				     ^
      symbol:   variable birth
      location: class PayrollSystemTest
    5 errors
    
     ----jGRASP wedge2: exit code for process is 1.
     ----jGRASP: operation complete.
    thanks

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Java Application-Employee Payroll System error PayrollSystemTest.java:56: error:

    Quote Originally Posted by khollinghead View Post
    ok I've corrected a view things. Here's the new code.
    Most of the error messages are self explanatory.

    Java Code:
     ----jGRASP exec: javac -g PayrollSystemTest.java
    
    PayrollSystemTest.java:56: error: cannot find symbol
    			if (currentEmployee.getBirthDate().getMonth() == BONUS_MONTH) {
    			                                  ^
      symbol:   method getMonth()
      location: class String
    you're calling getBirthDate() on the currentEmployee which returns a String, and then calling getMonth() on this, and Strings don't have this method. But more importantly, please look closely at that line of code because just a glance should tell you that it doesn't make sense. Don't you instead want to simply call the getMonth() method on the currentEmployee?

    Java Code:
    PayrollSystemTest.java:82: error: cannot find symbol
    		SalariedEmployee salariedEmployee = new SalariedEmployee(firstName, lastName, ssn, birth, month, salary);
    		                                                                                   ^
      symbol:   variable birth
      location: class PayrollSystemTest
    Here the compiler is telling you that you're trying to use a variable, birth, that doesn't exist in this scope. You can only use variables that exist inside of the scope where you're using it.

    Java Code:
    PayrollSystemTest.java:100: error: cannot find symbol
    		HourlyEmployee hourlyEmployee = new HourlyEmployee(firstName, lastName, ssn, birth, month, hourlyWages,
    		                                                                             ^
      symbol:   variable birth
      location: class PayrollSystemTest
    PayrollSystemTest.java:119: error: cannot find symbol
    		CommissionEmployee commissionEmployee = new CommissionEmployee(firstName, lastName, ssn, birth, month, 
    		                                                                                         ^
      symbol:   variable birth
      location: class PayrollSystemTest
    PayrollSystemTest.java:141: error: cannot find symbol
    				ssn, birth, month, grossSales, commissionRate, baseSalary);
    				     ^
      symbol:   variable birth
      location: class PayrollSystemTest
    Same for all the above errors. Again look in the method that holds the erroneous code and look to see where you declare the birth variable before trying to use it here (you don't), and fix this.

    The moral to all of this is to not look in fear and confusion at the error messages, but rather to try to understand what they are telling you, for usually the cause of the problem and then its solution can pretty easily be obtained from these messages.

Similar Threads

  1. Replies: 0
    Last Post: 01-21-2011, 12:43 PM
  2. Java Application fails to launch without error
    By javaguy78 in forum AWT / Swing
    Replies: 9
    Last Post: 11-16-2010, 06:25 PM
  3. Replies: 8
    Last Post: 12-30-2009, 11:40 AM
  4. error runing a java application
    By samjesse in forum Java Applets
    Replies: 5
    Last Post: 11-05-2009, 03:44 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •