示例#1
0
  public static void main(String[] args) {
    String csvFile = "C:/devel/EmployeeList.csv";
    List<Employee> jobs = new ArrayList<Employee>();
    ReadEmployeeList read = new ReadEmployeeList();
    read.readCSV(csvFile, jobs);

    try {
      for (Employee job : jobs) {

        String fullName = job.getFirstName() + " " + job.getLastName();
        String payperiod = read.calcPayPeriod(job.getMonth());
        int grossIncome = read.calcGrossIncome(job.getAnnualSalary());
        int netIncome =
            (int)
                (read.calcGrossIncome(job.getAnnualSalary())
                    - read.calcIncomeTax(job.getAnnualSalary()));
        int incomeTaxAmount = (int) read.calcIncomeTax(job.getAnnualSalary());
        System.out.println("Payslip information for Employee is:");
        System.out.println(
            fullName
                + ","
                + payperiod
                + ","
                + grossIncome
                + ","
                + incomeTaxAmount
                + ","
                + netIncome
                + ","
                + read.calcSuper(grossIncome, job.getSuperRate()));
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#2
0
  /**
   * This is a truly horrible way to make decisions. Very rigid and fragile!
   *
   * @param e - an employee object (not truly polymorphic!) employeeType - a String identifying the
   *     employee type. A constant (see above) should be used for this, but can you guarantee it
   *     will be? Are there other options? Hint: enum
   * @return the annual compensation for supported employee types
   */
  public double getAnnualCompensationForEmployee(Employee e, String employeeType) {
    double annualCompensation = 0;

    // One example of using fragile if logic to determine employee type.
    // If only we could use polymorphism instead!
    if (employeeType.equals(HOURLY_TYPE)) {
      annualCompensation = e.getAnnualWages();

    } else if (employeeType.equals(SALARIED_TYPE)) {
      annualCompensation = e.getAnnualSalary();

    } else {
      JOptionPane.showMessageDialog(null, ERROR_MSG, ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
    }

    return annualCompensation;
  }
示例#3
0
  SalarySlip generateFor(Employee employee) {
    AnnualAmount annualSalary = new AnnualAmount(employee.getAnnualSalary());
    MonthlyAmount nationalInsuranceContribution =
        nationalInsuranceCalculation.execute(annualSalary);
    MonthlyAmount grossSalary = grossSalaryCalculation.execute(annualSalary);
    MonthlyAmount taxFreeAllowance = taxFreeAllowanceCalculation.execute(annualSalary);
    MonthlyAmount taxableIncome = taxableIncomeCalculation.execute(annualSalary);
    MonthlyAmount taxablePayable = taxablePayableCalculation.execute(annualSalary);

    return aSalarySlip()
        .withEmployeeID(employee.getEmployeeID())
        .withName(employee.getName())
        .withGrossMonthlySalary(grossSalary.asFormattedAmount())
        .withNationalInsuranceMonthlyContribution(nationalInsuranceContribution.asFormattedAmount())
        .withTaxFreeMonthlyAllowance(taxFreeAllowance.asFormattedAmount())
        .withTaxableMonthlyIncome(taxableIncome.asFormattedAmount())
        .withTaxablePayable(taxablePayable.asFormattedAmount())
        .build();
  }
示例#4
0
  /**
   * This is another truly horrible way to make decisions. Very rigid and fragile!
   *
   * @param e - an employee object (not truly polymorphic!)
   * @return the annual compensation for supported employee types
   */
  public double getAnnualCompensationForEmployee(Employee e) {
    double annualCompensation = 0;

    // One example of using fragile if logic to determine employee type.
    // If only we could use polymorphism!
    // NOTE: you don't need both versions (the one above and this one).
    // Find a single, better way, using DIP principles.
    if (e instanceof HourlyEmployee) {
      annualCompensation = e.getAnnualWages();

    } else if (e instanceof SalariedEmployee) {
      annualCompensation = e.getAnnualSalary();

    } else {
      JOptionPane.showMessageDialog(null, ERROR_MSG, ERROR_TITLE, JOptionPane.ERROR_MESSAGE);
    }

    return annualCompensation;
  }