434,677 Members | 1,136 Online
Need help? Post your question and get tips & solutions from a community of 434,677 IT Pros & Developers. It's quick & easy.

# Write a program to calculate Payroll of employee

 P: 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 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
7 Replies

 Expert 100+ P: 1,123 What errors you are getting? Regards Dheeraj Joshi Apr 19 '10 #2

 P: 2 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;     }       public double federalTax(double gross)     {         return FEDERAL_TAX_WITHHOLDING_RATE * gross;     }       public double stateTax(double gross)     {         return STATE_TAX_WITHHOLDING_RATE * gross;     }         public String getName() {         return name;     }         public void setName(String name) {         this.name = name;     }         public double getHoursWorked() {         return hoursWorked;     }         public void setHoursWorked(double hoursWorked) {         this.hoursWorked = hoursWorked;     }         public double getHourlyPayRate() {         return hourlyPayRate;     }         public void setHourlyPayRate(double hourlyPayRate) {         this.hourlyPayRate = hourlyPayRate;     }   }   // @Copyright: Swaran Bindra   import java.util.*;   public class PayrollDriver  {     public static void main(String args[])     {         Scanner input =  new Scanner(System.in);         PayrollCalc data = new PayrollCalc();           System.out.println("Enter your name: ");         data.setName(input.next());           System.out.println("Number of Hours Worked: ");         data.setHoursWorked(Double.parseDouble(input.next()));           System.out.println("Hourly Pay Rate: ");         data.setHourlyPayRate(Double.parseDouble(input.next()));           double grossAmount = data.grossPay(data.getHourlyPayRate(), data.getHoursWorked());           System.out.println();         System.out.println("------------------------------------");         System.out.println("Name: " + data.getName());         System.out.println("Hours Worked: " + data.getHoursWorked() + "hrs");         System.out.println("Pay Rate: \$" + data.getHourlyPayRate());         System.out.println("Gross Pay: \$" + grossAmount + '\n');         System.out.println("DEDUCTIONS");         System.out.println("Federal Tax Withholding (20%): \$" + data.federalTax(grossAmount));         System.out.println("State Tax Withholding (9%): \$" + data.stateTax(grossAmount));         System.out.println("Total Deductions: \$" + (data.federalTax(grossAmount) + data.stateTax(grossAmount)));         System.out.println("Net Pay: \$" + (grossAmount - (data.federalTax(grossAmount) + data.stateTax(grossAmount))));             input.close();     }   }   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

 Expert 100+ P: 785 Hey Swaran, can you please tell us what errors you are getting? Just copy the messages and list them here. Aug 12 '15 #4

 P: 2 Sorry, this program is in response to a previous query by habsy Aug 12 '15 #5

 Expert 100+ P: 785 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

 Expert Mod 10K+ P: 12,365 @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

 Expert 100+ P: 785 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