/** Name: Cameron Lewis Student ID: 16254966 **/ // Paycheck.java // // ICS H22 Fall 2005 // Lab 2: The Price You Pay // // You will need to complete this class by implementing the constructor, the // toString() method, along with any other code you need to complete it. public class Paycheck { private String name; private int hours; private int gross; private int taxes; private int netPay; private String empInfo; // The constructor takes the information necessary to initialize a // paycheck. In our program, that consists of an employee, the number // of hours worked, the gross pay (in cents), and the tax (in cents). public Paycheck(Employee employee, int hoursWorked, int grossPay, int tax) { name = employee.getName(); hours = hoursWorked; gross = grossPay; taxes = tax; netPay = grossPay - tax; empInfo = employee.toString(); } // toString() returns a formatted String representation of the paycheck. // An example of the output for this method is a String that looks like // this: // // Paycheck for John Doe (hourly, $26.50/hr) // // Hours Worked: 40 // Gross Pay: $1,060.00 // Tax: $212.00 // Net Pay: $848.00 // // Don't forget that you can use String.format() to do a lot of the // formatting work for you. Also, the CurrencyFormat.format() method // that I provided will be useful in turning monetary amounts into // representations like "$1,060.00". public String toString() { String s = ""; s += "--------------------------------------------------------------------------------"; s += String.format("\n%-15s %s\n\n", "Paycheck for:", empInfo); s += String.format("%20s%20d\n", "Hours Worked:", hours); s += String.format("%20s%20s\n", "Gross Pay:", CurrencyFormat.format(gross)); s += String.format("%20s%20s\n", "Tax:", CurrencyFormat.format(taxes)); s += String.format("%20s%20s\n", "Net Pay:", CurrencyFormat.format(netPay)); s += "--------------------------------------------------------------------------------"; return s; } }