// NAME: Liane Nakamura // STUDENT ID: 25806927 //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 { Employee employee; int hoursWorked; int grossPay; int tax; // 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) { this.employee = employee; this.hoursWorked = hoursWorked; this.grossPay = grossPay; this.tax = tax; } // 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 += "\n" + "Paycheck for " + employee + "\n"; s += String.format("%15s: %12s\n", "Hours Worked", hoursWorked); s += String.format("%15s: %15s\n", "Gross Pay", CurrencyFormat.format(grossPay)); s += String.format("%15s: %15s\n", "Tax", CurrencyFormat.format(tax)); s += String.format("%15s: %15s\n", "Net Pay", CurrencyFormat.format(grossPay - tax)); return s; } }