954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Payroll Program

I am having some difficulty, any advice would be gladly appreciated. Thanks in advance.

Write a program that reads the following information and prints a payroll statement:

Employee's name
Number of hours worked in a week
Hourly pay rate
Federal tax withholding rate
State tax withholding rate

Enter employee's name: Smith
Enter hours: 10
Enter hourly pay rate: 6.75 <-----Obtain input
Enter federal tax withholding rate: 0.20
Enter state tax withholding rate: 0.09
Employee name: Smith

Hours Worked: 10.0
Pay Rate: $6.75
Gross Pay: $67.5
Deductions:
Federal Withholding (20.0%): $13.5 <----Display output
State Withholding (9.0%): $6.07
Total Deduction: $19.57
Net Pay: $47.92

import java.util.Scanner;
 
public class Payroll
{
   public static void main (String []args)
   {
       String name;
       int hours;
       double rate;
       double fedTax;
       double stateTax;
 
 
       Scanner input = new Scanner(System.in);
 
       System.out.print("Enter employee name: ");
 
 
       System.out.print("Enter number of hours worked in a week: ");
 
 
       System.out.print("Enter hourly pay rate: ");
 
 
       System.out.print("Enter federal tax withholding rate: ");
 
 
       System.out.print("Enter state tax withholding rate: ");
 
       System.out.println("Employee Name: " + string)
 
 
       double grossPay;
 
       grossPay = rate * hours;
 
       double fedwithHolding;
 
       fedwithHolding = fedTax * grossPay;
 
       double statewithHolding;
 
       statewithHolding = stateTax * grossPay;  
 
       double deduction;
 
       deduction = fedwithHolding + statewithHolding;
 
 
 
 
 
       double netPay;
 
       netPay = (grossPay) - deduction;
 
 
 
       System.out.println("The netpay is " +netPay);
       }
}
shivers20
Newbie Poster
1 post since May 2007
Reputation Points: 10
Solved Threads: 0
 

You forgot to mention what difficulties???

,but this seems to be obvious. You do not know how to use Scanner ! ! !
So take your time and read API reference for Scanner http://java.sun.com/javase/6/docs/api/java/util/Scanner.html and do it. Methods like nextLine(), nextInt() or nextDouble() can be your friends...
But consider that user enter wrong data what then? Are you supposed to take care of it or so far user is expected only to enter corrcet data.

PS: Other which may have temptentation to give him quick solution. Please don't do it! shivers20 needs to do it on his own. And there is no problem to provide additional info if he/she show interest, also all what he need is in advice above

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

If you need help with this program please contact me at [email address removed]

mpilot
Newbie Poster
1 post since May 2007
Reputation Points: 10
Solved Threads: 0
 

Can you please help since I have a program like yours but I have to make it in 2 different windows{i.e. 2 different class} but i have to do it using arrays....and I don't now how I can do it... Can you pls help me....

I am having some difficulty, any advice would be gladly appreciated. Thanks in advance. Write a program that reads the following information and prints a payroll statement: Employee's name Number of hours worked in a week Hourly pay rate Federal tax withholding rate State tax withholding rate Enter employee's name: Smith Enter hours: 10 Enter hourly pay rate: 6.75 <-----Obtain input Enter federal tax withholding rate: 0.20 Enter state tax withholding rate: 0.09 Employee name: Smith Hours Worked: 10.0 Pay Rate: $6.75 Gross Pay: $67.5 Deductions: Federal Withholding (20.0%): $13.5 <----Display output State Withholding (9.0%): $6.07 Total Deduction: $19.57 Net Pay: $47.92

import java.util.Scanner;
 
public class Payroll
{
   public static void main (String []args)
   {
       String name;
       int hours;
       double rate;
       double fedTax;
       double stateTax;
 
 
       Scanner input = new Scanner(System.in);
 
       System.out.print("Enter employee name: ");
 
 
       System.out.print("Enter number of hours worked in a week: ");
 
 
       System.out.print("Enter hourly pay rate: ");
 
 
       System.out.print("Enter federal tax withholding rate: ");
 
 
       System.out.print("Enter state tax withholding rate: ");
 
       System.out.println("Employee Name: " + string)
 
 
       double grossPay;
 
       grossPay = rate * hours;
 
       double fedwithHolding;
 
       fedwithHolding = fedTax * grossPay;
 
       double statewithHolding;
 
       statewithHolding = stateTax * grossPay;  
 
       double deduction;
 
       deduction = fedwithHolding + statewithHolding;
 
 
 
 
 
       double netPay;
 
       netPay = (grossPay) - deduction;
 
 
 
       System.out.println("The netpay is " +netPay);
       }
}
Tizzie
Newbie Poster
3 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

I am having some difficulty, any advice would be gladly appreciated. Thanks in advance. Write a program that reads the following information and prints a payroll statement: Employee's name Number of hours worked in a week Hourly pay rate Federal tax withholding rate State tax withholding rate Enter employee's name: Smith Enter hours: 10 Enter hourly pay rate: 6.75 <-----Obtain input Enter federal tax withholding rate: 0.20 Enter state tax withholding rate: 0.09 Employee name: Smith Hours Worked: 10.0 Pay Rate: $6.75 Gross Pay: $67.5 Deductions: Federal Withholding (20.0%): $13.5 <----Display output State Withholding (9.0%): $6.07 Total Deduction: $19.57 Net Pay: $47.92

import java.util.Scanner;
 
public class Payroll
{
   public static void main (String []args)
   {
       String name;
       int hours;
       double rate;
       double fedTax;
       double stateTax;
 
 
       Scanner input = new Scanner(System.in);
 
       System.out.print("Enter employee name: ");
 
 
       System.out.print("Enter number of hours worked in a week: ");
 
 
       System.out.print("Enter hourly pay rate: ");
 
 
       System.out.print("Enter federal tax withholding rate: ");
 
 
       System.out.print("Enter state tax withholding rate: ");
 
       System.out.println("Employee Name: " + string)
 
 
       double grossPay;
 
       grossPay = rate * hours;
 
       double fedwithHolding;
 
       fedwithHolding = fedTax * grossPay;
 
       double statewithHolding;
 
       statewithHolding = stateTax * grossPay;  
 
       double deduction;
 
       deduction = fedwithHolding + statewithHolding;
 
 
 
 
 
       double netPay;
 
       netPay = (grossPay) - deduction;
 
 
 
       System.out.println("The netpay is " +netPay);
       }
}


thanks a lot for the program.u r real people to work with.

Seizmic
Newbie Poster
1 post since Apr 2010
Reputation Points: 8
Solved Threads: 0
 

Nice first post. Hope you have a good time with that program that the OP said doesn't work that was written years ago.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You