473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Write a program to calculate Payroll of employee

1
The below are the question given; Please help.


(Payroll) Write a program that reads the following information and prints payroll statements in show message dialog box.
These are the inputs:

Employees Full Name (e.g. Mohammed Al Zakwani)
Numbers of Hours worked in a week (e.g. 40 hours)
Hourly Pay Rate (e.g. 6.75)
Federal Tax withholding rate (e.g. 20%)
State Tax withholding rate (e.g. 9%)

You should calculate:

Gross Pay = hourly pay rate * numbers of hours worked in a week.
Federal Tax withholding = Federal Tax withholding rate * gross pay
State Tax withholding = State Tax withholding rate * gross pay
Total Deductions = Federal Tax withholding + State Tax withholding
Net Pay = Gross Pay + Total Deductions

Output should be

Employees Full Name: Mohammed Al Zakwani
Numbers of Hours worked in a week: 40 hours
Hourly Pay Rate: $ 6.75
Gross Pay: $270
Deductions:
Federal Tax withholding (20%): $54
State Tax withholding rate (9%) : $24.3
Total Deductions: $78.3
Net Pay: $191.7

I tried to do as below but i'm getting alot of error;
Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. class payroll {
  4. {
  5.    public static void main(String[] args)
  6.    {
  7.       Scanner input = new Scanner(System.in);
  8.  
  9.       System.out.println("Enter employee's name:");
  10.       String employee = input.next();
  11.  
  12.       System.out.println("Enter number of hours worked:");
  13.       double  hours = input.nextDouble();
  14.  
  15.       System.out.println("Enter hourly pay rate:");
  16.       double  pay = input.nextDouble();
  17.  
  18.       double  gross_pay = pay * hours;
  19.  
  20.       System.out.println("Enter federal tax withholding rate:");
  21.       double  fedtax = input.nextDouble();
  22.       double fedtaxr = fedtax * 0.20;
  23.  
  24.       System.out.println("Enter state tax withholding rate:");
  25.       double  statetax = input.nextDouble();
  26.  
  27.       double statetaxr = statetax * 0.20;
  28.  
  29.       double deductions = fedtaxr + statetaxr;
  30.  
  31.       double total_pay = gross_pay - deductions;
  32.  
  33.       System.out.println("Employee name: " + employee);
  34.  
  35.       System.out.println("Hours worked: " + hours);
  36.  
  37.       System.out.println(" Enter payrate: " + pay);
  38.  
  39.       System.out.println(" Enter gross pay: " + gross_pay);
  40.  
  41.       System.out.println(" Deductions: ");
  42.       System.out.println("\t Federdal Withholding (20.0%): " + fedtaxr);
  43.       System.out.println("\t State Withholding (9.0%)" + statetaxr);
  44.       System.out.println("\t Total deductions:" + deductions);
  45.       System.out.println("Total pay: " + total_pay);
  46.    }
  47. }
Apr 17 '10 #1
7 113121
Dheeraj Joshi
1,123 Expert 1GB
What errors you are getting?

Regards
Dheeraj Joshi
Apr 19 '10 #2
Swaran
2
Here's the program in Java.....

Expand|Select|Wrap|Line Numbers
  1. // @Copyright: Swaran Bindra
  2.  
  3.  
  4. public class PayrollCalc 
  5. {
  6.     private String name;
  7.     private double hoursWorked;
  8.     private double hourlyPayRate;
  9.     private static final double FEDERAL_TAX_WITHHOLDING_RATE = 0.20;
  10.     private static final double STATE_TAX_WITHHOLDING_RATE = 0.09;
  11.  
  12.  
  13.     public PayrollCalc()
  14.     {
  15.  
  16.     }
  17.  
  18.     public PayrollCalc(String n, double hw, double hpr)
  19.     {
  20.         this.name = n;
  21.         this.hoursWorked = hw;
  22.         this.hourlyPayRate = hpr;
  23.     }
  24.  
  25.     public double grossPay(double hourlyRate, double hrsWorked)
  26.     {
  27.         double grossPay = (hourlyRate * hrsWorked);
  28.         return grossPay;
  29.     }
  30.  
  31.     public double federalTax(double gross)
  32.     {
  33.         return FEDERAL_TAX_WITHHOLDING_RATE * gross;
  34.     }
  35.  
  36.     public double stateTax(double gross)
  37.     {
  38.         return STATE_TAX_WITHHOLDING_RATE * gross;
  39.     }
  40.  
  41.  
  42.     public String getName() {
  43.         return name;
  44.     }
  45.  
  46.  
  47.     public void setName(String name) {
  48.         this.name = name;
  49.     }
  50.  
  51.  
  52.     public double getHoursWorked() {
  53.         return hoursWorked;
  54.     }
  55.  
  56.  
  57.     public void setHoursWorked(double hoursWorked) {
  58.         this.hoursWorked = hoursWorked;
  59.     }
  60.  
  61.  
  62.     public double getHourlyPayRate() {
  63.         return hourlyPayRate;
  64.     }
  65.  
  66.  
  67.     public void setHourlyPayRate(double hourlyPayRate) {
  68.         this.hourlyPayRate = hourlyPayRate;
  69.     }
  70.  
  71. }
  72.  
  73. // @Copyright: Swaran Bindra
  74.  
  75. import java.util.*;
  76.  
  77. public class PayrollDriver 
  78. {
  79.     public static void main(String args[])
  80.     {
  81.         Scanner input =  new Scanner(System.in);
  82.         PayrollCalc data = new PayrollCalc();
  83.  
  84.         System.out.println("Enter your name: ");
  85.         data.setName(input.next());
  86.  
  87.         System.out.println("Number of Hours Worked: ");
  88.         data.setHoursWorked(Double.parseDouble(input.next()));
  89.  
  90.         System.out.println("Hourly Pay Rate: ");
  91.         data.setHourlyPayRate(Double.parseDouble(input.next()));
  92.  
  93.         double grossAmount = data.grossPay(data.getHourlyPayRate(), data.getHoursWorked());
  94.  
  95.         System.out.println();
  96.         System.out.println("------------------------------------");
  97.         System.out.println("Name: " + data.getName());
  98.         System.out.println("Hours Worked: " + data.getHoursWorked() + "hrs");
  99.         System.out.println("Pay Rate: $" + data.getHourlyPayRate());
  100.         System.out.println("Gross Pay: $" + grossAmount + '\n');
  101.         System.out.println("DEDUCTIONS");
  102.         System.out.println("Federal Tax Withholding (20%): $" + data.federalTax(grossAmount));
  103.         System.out.println("State Tax Withholding (9%): $" + data.stateTax(grossAmount));
  104.         System.out.println("Total Deductions: $" + (data.federalTax(grossAmount) + data.stateTax(grossAmount)));
  105.         System.out.println("Net Pay: $" + (grossAmount - (data.federalTax(grossAmount) + data.stateTax(grossAmount))));
  106.  
  107.  
  108.         input.close();
  109.     }
  110.  
  111. }
  112.  
Output:
Name: swaran
Hours Worked: 40.0 hrs
Pay Rate: $6.75
Gross Pay: $270.0

DEDUCTIONS
Federal Tax Withholding (20%): $54.0
State Tax Withholding (9%): $24.3
Total Deductions: $78.3
Net Pay: $191.7



Regards
Swaran
Aug 11 '15 #3
chaarmann
785 Expert 512MB
Hey Swaran, can you please tell us what errors you are getting?
Just copy the messages and list them here.
Aug 12 '15 #4
Swaran
2
Sorry, this program is in response to a previous query by habsy
Aug 12 '15 #5
chaarmann
785 Expert 512MB
Swaran, I think there is a misunderstanding.
Listing the program is fine, but we also need the exact error message. You may think, we can run the program of our own on our system and see the error message? Nope. Your system can behave completely different dependent on hardware and software.
Also it is some piece of work for us to run your program. On the other side it should cost you only a few seconds to copy the message that you see on your screen into this forum post. Please do not put an unnecessary burden on us like running the program in order to help you. Keep in mind that we are not getting paid by helping you. It's just a favor we do for you.
Aug 13 '15 #6
Rabbit
12,516 Expert Mod 8TB
@chaarmann, I believe their post is supposed to be the answer to the thread, not a question.

@swaran, Please use code tags when posting code or formatted data.
Aug 13 '15 #7
chaarmann
785 Expert 512MB
Hi Swaran.
if that is true what Rabbit believes (why didn't you tell me ?), then I like to say "Thank you" to you for posting the solution, so that others with the same problems can benefit.
Aug 14 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Simon Wigzell | last post by:
I recently wrote a program with MS Visual Studio C++, sent it off to the client where it didn't run, after some probing I discover they are on a Mac! My program is a MSF interface that is really...
0
by: Tom | last post by:
I am new to hardware programming. I need to write a program for reading data from Card Reader which connects to the PC windows 2000/XP OS through Interfacing The Serial / RS-232 Port / USB /...
0
by: alem | last post by:
Hi Alem: To calculate Employee work expereance in Ms-Access what shall I do b/c I tried by the following formulas bu I got three or four month different I can't get exact service year and I...
8
by: Serenityquinn15 | last post by:
Hi! I just want to know, how to calculate the employee timesheet it's a part of payroll system. and it is my first time to create a system like this. I need to determine the Overtime, Late and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.