CSCI 161: Introduction to Programming I
Spring 2007
Lab 6: Paycheck (Writing Classes and Conditionals)

Due Thursday, March 22nd at beginning of lab period


Overview

Design and implement a class called Paycheck that contains instance data that represents an employee's name, type, hours worked, pay rate, tax rate, and whether (s)he needs to pay the occupational tax.

 

To represent the type of employee, use an instance variable of type EmployeeType, a public enum in the Paycheck class. Use the following employee types: Intern, Regular, and Contractor. Interns are paid straight overtime (the same as their regular wages), regular employees are paid time-and-a-half, and contractors are paid double-time. Assume a 40-hour work week.

 

Include getter and setter methods for the name, employee type, hours worked, pay rate, tax rate, and whether the employee must pay the occupational tax (twelve total accessor methods).

 

Include a method computeGross to compute and return the gross earnings for a paycheck, along with a method computeNet to compute and return the net earnings (net is the "take-home" pay, so taxes are removed). If the occupational tax needs to be paid, an additional $10 in taxes should be subtracted from the net pay AFTER paying the taxes according to the tax rate. computeNet should call the computeGross method.

 

Include a toString method that returns a multi-line description of the paycheck, formatted as shown below. The toString method must call the computeGross and computeNet methods.

 

Create a driver class called Payroll, whose main method instantiates a Paycheck. The information about the paycheck will come from the user.

 

This project requires two Java source files: Paycheck.java and Payroll.java. Payroll.java will contain the Payroll class and method main.

 

Input Specification

Prompt the user for the details of a paycheck. Sample input (shown in bold) along with system prompts is shown below.

Enter the employee name: Ted Brown
Enter the employee type (intern, regular, contractor): Regular
Enter the hours worked: 50
Enter the hourly rate: 11.00
Enter the tax rate: .25
Does employee need to pay the occupational tax (y/n)? y

 

Note that it should not matter whether the user enters uppercase or lowercase (or a mix of the two) for the employee type or "y" or "n" for the occupational tax.

 

Output Specification

After instantiating the Paycheck object, and setting the various attributes using the user's input, display the paycheck details using System.out.println (paycheckObject) to obtain output like that shown below (the values in the output will vary based on the input). Use only console-based input and output.

 

Paycheck for Ted Brown:

     Employee type: Regular

     Hours worked: 50

     Hourly rate: $11.00

     Tax rate: 25%

     Occupation tax: $10.00

     Gross pay: $605.00

     Net pay: $443.75

 

If the occupational tax is deducted from the paycheck, then $10.00 should be displayed as shown above, otherwise $0.00 should be displayed.

 

Required Methods

public Paycheck ()

 

public void   setName (String name)

public String getName ()

 

public void setEmployeeType  (EmployeeType empType)

public EmployeeType getEmployeeType  ()

 

public void setHoursWorked (int hours)

public int  getHoursWorked ()

 

public void   setHourlyRate (double rate)

public double getHourlyRate ()

 

public void   setTaxRate (double tax)

public double getTaxRate ()

 

public void    setOccupationTax (boolean pay)

public boolean getOccupationTax ()

 

public double computeGross ()

public double computeNet   ()

 

public String toString     ()

 

Additional Requirements

Use a switch statement (switch on employee type) in the Paycheck class (preferred method computeGross).

 

Hints

This is a fairly involved class. Do not limit your testing to the example shown above. Ensure that your class works for all employee types and various data.

 

Use the NumberFormat class to get the output shown above. Do not format any output in your driver class. Rely on the toString method.

 

The only instance data should be the employee's name, type, hours worked, pay rate, tax rate, and need to pay the occupational tax. Avoid storing net or gross pay as instance data.

 

When you read the employee type from the user, be sure to do the string comparison using the equals method of the String class, not operator ==.