473,659 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write a program to calculate Payroll of employee

1 New Member
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 113253
Dheeraj Joshi
1,123 Recognized Expert Top Contributor
What errors you are getting?

Regards
Dheeraj Joshi
Apr 19 '10 #2
Swaran
2 New Member
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 Recognized Expert Contributor
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 New Member
Sorry, this program is in response to a previous query by habsy
Aug 12 '15 #5
chaarmann
785 Recognized Expert Contributor
Swaran, I think there is a misunderstandin g.
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 Recognized Expert Moderator MVP
@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 Recognized Expert Contributor
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
6389
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 only 2 File buttons with corresponding text fields. The actual guts of the program is a C file that accepts 2 file names as arguments and reads from one file, manipulates the string and writes it to another file. Java and C syntax are very similar....
0
2046
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 / Bluetooth / Infrared. May I ask does serial port equal to com port? The program needs to read and write data of the smart card which places on top of the card reader. The card reader has serveral models, they support
0
1190
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 will display also with decimal number. Service year: ((()/30)/12) a person emplyed in different organization, fist I calcualte Begin and End date of emploment date then I use the above formula. Diff represents Begin date-End date Please...
8
6412
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 undertime of each employee, Please Help me... Thanks.... :)
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8535
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.