In: Computer Science
General Description: Write a program that processes weekly payroll for a small company. The program starts with printing a logo then asking for the total number of employees for the week. The program then inputs data for each individual employee and prints a paystub. At the end, it prints a report based on data for all employees.
Gross Pay: The company has two types of employees: Hourly and Salaried
- Hourly employees have an hourly wage, and are paid overtime (1.5 times the hourly wage) for any time worked over 40 hours. The program must ask for Hourly Rate and Number of hours worked, then calculates the Gross pay correctly.
- Salaried employees have a weekly Gross Salary, not based on the number of hours worked. So the program only asks for the Gross Salary.
Taxes: Taxes must be deducted from the paycheck of all employees, regardless of employee type:
- Federal Income Tax is a percentage of the Gross Pay. The Federal Tax Rate is determined as follows:
Gross Pay at least Gross Pay at most Federal Tax Rate 0.00 599.99 0% 600.00 799.00 4% 800.00 1099.99 8% 1100.00 Any above 1100 12%
- Social Security is 3% of Gross Pay.
- State Income Tax is 6% of any Gross Pay over $500 (so if Gross is $600 that’s 0.06% of (600-500) = $100, which is $6. For a Gross $500 and under, the tax is $0). In other words, “The first $500 is not taxed for anyone”
- Local Income Tax is 1.5% for local residents and 1% for non-residents.
Net Pay is the Gross minus the taxes deducted.
Report: The report includes the sum of each tax and the net pay for all employees, except that the amount for Social Security is double the total amount deducted from employees’ checks.
Bottom-Up Detailed Design:
AskEmplType(): Asks the user to enter the employee type (H,h,S,s), validating the input. Returns the value entered. GetHourlyGross(): Asks the user to enter the Hourly Rate and Hours worked. Calculates the gross, giving “time and a half” for any hours over 40. Returns the gross calculated. (Ex: rate=25, hours=45: gross = (40 +( (45-40) x1.5)) x 25
AskResident(): Asks the user if the employee is a local resident (Y,y,N,n), validating the input. Returns the answer.
CalcFedTax(): Given the gross, calculates and returns the amount of federal tax.
CalcStateTax(): Given the gross, calculates and returns the amount of state tax.
CalcLocalTax(): Given the gross and the resident status (Y/y/N/n), calculates and returns the amount of local tax.
PrintStub(): Given the first and last name, gross, taxes and net, prints the payroll stub for the employee (should do NO calculations nor “ask the user”, just prints. Exception: it may calculate the TOTAL TAX by adding up the tax numbers given; or better, calculate it in ProcessEmployee() and pass it intoPrintStub() as another argument).
ProcessEmployee: Given the employee number, and invoking the sub functions indicated, does all processing for the employee. Returns the first name, last name, gross, net pay, fed tax, ssi tax, state tax and local tax of the employee processed. Note: functions are not defined for some operations of processing an employee (ex: Enter names, enter weekly salary for a salaried employee). The designers deemed these activities to be too trivial to be their own function. Therefore, it is the job of ProcessEmployee() to carry out these minor tasks, in addition to coordinating/invoking the sub-functions.
PrintLogo(): just prints the logo
AskNumEmployees(): Asks the user to enter the number of employees to process, validating the number as 1 or more. Returns the number entered.
UpdateTotals(): Given the gross, net pay, fed tax, ssi tax, state tax and local tax of the last employee processed, adds these numbers to the totals for all employees. Returns the updated totals.
PrintReport(): given the totals for gross, net pay, fed tax, ssi tax, state tax and local tax of all employees processed, prints the report as shown above. Note that the amount of ssi tax printed is two times the given amount.
Main(): invokes the functions indicated as needed to control the entire payroll program. Should do a system pause at the very end.
import java.util.Scanner;
class payroll {
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter employee's name:");
String employee = input.next();
System.out.println("Enter number of hours worked:");
double hours = input.nextDouble();
System.out.println("Enter hourly pay rate:");
double pay = input.nextDouble();
double gross_pay = pay * hours;
System.out.println("Enter federal tax withholding rate:");
double fedtax = input.nextDouble();
double fedtaxr = fedtax * 0.20;
System.out.println("Enter state tax withholding rate:");
double statetax = input.nextDouble();
double statetaxr = statetax * 0.20;
double deductions = fedtaxr + statetaxr;
double total_pay = gross_pay - deductions;
System.out.println("Employee name: " + employee);
System.out.println("Hours worked: " + hours);
System.out.println(" Enter payrate: " + pay);
System.out.println(" Enter gross pay: " + gross_pay);
System.out.println(" Deductions: ");
System.out.println("\t Federdal Withholding (20.0%): " +
fedtaxr);
System.out.println("\t State Withholding (9.0%)" +
statetaxr);
System.out.println("\t Total deductions:" + deductions);
System.out.println("Total pay: " + total_pay);
}
}
Apr 17 '10 #1
Post Reply
Share this Question
Share on Google+
7 Replies
Dheeraj Joshi
Expert 100+
P: 1,123
Dheeraj Joshi
What errors you are getting?
Regards
Dheeraj Joshi
Apr 19 '10 #2
reply
P: 2
Swaran
Here's the program in Java.....
Expand|Select|Wrap|Line Numbers
// @Copyright: Swaran Bindra
public class PayrollCalc
{
private String name;
private double hoursWorked;
private double hourlyPayRate;
private static final double FEDERAL_TAX_WITHHOLDING_RATE =
0.20;
private static final double STATE_TAX_WITHHOLDING_RATE =
0.09;
public PayrollCalc()
{
}
public PayrollCalc(String n, double hw, double hpr)
{
this.name = n;
this.hoursWorked = hw;
this.hourlyPayRate = hpr;
}
public double grossPay(double hourlyRate, double hrsWorked)
{
double grossPay = (hourlyRate * hrsWorked);
return grossPay;
}