/ Published in: Java
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import java.io.*; public class PayrollApp { // Data Objects ( private Employees empTable; private static final MyString REPORT_HEADER_A = new MyString("Employee Pay Hours Gross Tax Net"); private static final MyString REPORT_HEADER_B = new MyString("Name Rate Worked Pay Amount Pay"); private static final MyString REPORT_HEADER_C = new MyString("====================== ======== ========== ========== ========== =========="); private static final MyString WORD_TOTALS = new MyString("Totals:"); private static final MyString WORD_AVERAGES = new MyString("Averages:"); // ) // Constructors ( public PayrollApp() { empTable = new Employees(); } public PayrollApp(HourlyEmployee e) { empTable = new Employees(e); } public PayrollApp(PiecedEmployee e) { empTable = new Employees(e); } public PayrollApp(SalariedEmployee e) { empTable = new Employees(e); } public PayrollApp(Employees e) { empTable = e; } empTable = new Employees(file); } // ) // Accessors ( public Employees getEmps() { return new Employees(empTable); } // ) // Mutators ( public MyString tableHeader() { return new MyString(" " + REPORT_HEADER_A + "\n " + REPORT_HEADER_B + "\n " + REPORT_HEADER_C); } public MyString[] tableRows() { MyString[] rows = new MyString[empTable.size()]; for (int i=0; i<empTable.size(); i++) { HourlyEmployee e = (HourlyEmployee)empTable.employee(i); rows[i] = new MyString(" " + e.formattedName().left(22) + " " + e.payRate().myString(2).right(8) + " " + e.hours().myString(2).right(10) + " " + e.grossPay().myString(2).right(10) + " " + e.taxAmount().myString(2).right(10) + " " + e.netPay().myString(2).right(10)); } return rows; } for (int i=0; i<empTable.size(); i++) { total = total .plus (((HourlyEmployee)empTable.employee(i)).payRate()); } return total; } for (int i=0; i<empTable.size(); i++) { total = total .plus (((HourlyEmployee)empTable.employee(i)).hours()); } return total; } for (int i=0; i<empTable.size(); i++) { total = total .plus (empTable.employee(i).grossPay()); } return total; } for (int i=0; i<empTable.size(); i++) { total = total .plus (empTable.employee(i).taxAmount()); } return total; } for (int i=0; i<empTable.size(); i++) { total = total .plus (empTable.employee(i).netPay()); } return total; } return totalPayRate() .over (empTable.size()); } return totalHours() .over (empTable.size()); } return totalGross() .over (empTable.size()); } return totalTax() .over (empTable.size()); } return totalNet() .over (empTable.size()); } public MyString totalsRow() { return new MyString(" " + WORD_TOTALS.left(22) + " " + totalPayRate().myString(2).right(8) + " " + totalHours().myString(2).right(10) + " " + totalGross().myString(2).right(10) + " " + totalTax().myString(2).right(10) + " " + totalNet().myString(2).right(10)); } public MyString averagesRow() { return new MyString(" " + WORD_AVERAGES.left(22) + " " + avgPayRate().myString(2).right(8) + " " + avgHours().myString(2).right(10) + " " + avgGross().myString(2).right(10) + " " + avgTax().myString(2).right(10) + " " + avgNet().myString(2).right(10)); } // ) }