Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: payroll code problem

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question payroll code problem

    Im really new to java and need help with class.

    Here is what im trying to do


    Write a class that accepts a user's hourly rate of pay and the number of hours worked.
    Display the user's gross pay (gross pay = hours worked * hourly rate),
    the tax withheld (tax withheld = gross pay * tax rate) and the net pay
    (net pay = gross pay - tax withheld).Use a named constant for storing the tax rate of
    0.15

    Here is my Code:

     
    import java.util.Scanner;
     
    class Tutorial
    {
    public static void main(String[] args);
    {
     
    Scanner kb = new Scanner(sysem.in);
     
    double = hourlyrate;
    double = hoursworked;
    double = grosspay;
    double = netpay;
    double = taxrate 0.15;
    double = taxwithheld;
     
    System.out.println("Please enter rate of pay?" );
    hourlyrate = kb.nextdouble();
     
    System.out.println("Hours Worked?" );
    hoursworked = kb.nextdouble();
     
    System.out.println("Gross pay:" )+(grosspay = hoursworked*hourlyrate);
     
    System.out.println("Tax Withheld:" )+(taxwithheld= grosspay*taxrate);
     
    System.out.println("netpay:" )+(netpay= Grosspay-taxwithheld);
     
    }
    }


  2. #2
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default Re: payroll code problem

    Weldone JJAus! You tried, but not quite.
    Firstly, you declare the primitive types such as double as:
     double hourlyRate;
    and not
     double = hourlyrate;
    Note my use of capital 'R' for rate.

    Secondly, a convention for declaring constants:
     final double TAX_RATE = 0.15;

    Thirdly, your use of parenthesis seem weird to me. Overall, you really need to do more studying to master the basics of java before coming to forums to post questions.
    Who holds the KEY to all knowledge?

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: payroll code problem

    Overall, you really need to do more studying to master the basics of java before coming to forums to post questions.
    You're off base, Mugambbo. Advice and guidance to better understand Java and programming basics is one of the main reasons for coming to this forum and others like it. It's what we do.

    @JJAus: Thank you for taking the time to learn to post your code correctly.

    What's your question? What help do you need?

    This statement (and the others like it) do not require the 'variable = ' part, and your use of parentheses is incorrect:

    System.out.println("Gross pay:" )+(grosspay = hoursworked*hourlyrate);

    and can be reduced/corrected to:

    System.out.println( "Gross pay: " + (hoursworked*hourlyrate) );

  4. #4
    Junior Member
    Join Date
    Feb 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: payroll code problem

    Thank you for the help, fixed all the errors

    import java.util.Scanner;
     
    	class Payroll
    {
    	public static void main(String[] args)
    	{
     
    	Scanner kb = new Scanner(System.in);
     
    	double hourlyrate;
    	double hoursworked;
    	double grosspay;
    	double netpay;
    	double taxrate = 0.15;
    	double taxwithheld;
     
    	System.out.println("Please enter rate of pay?" );
    	hourlyrate = kb.nextDouble();
     
    	System.out.println("Hours Worked?" );
    	hoursworked = kb.nextDouble();
     
    	grosspay = hoursworked*hourlyrate;
     
    	System.out.println("Gross pay: " +grosspay);
     
    	taxwithheld= grosspay*taxrate;
     
    	System.out.println("Tax Withheld: " +taxwithheld);
     
    	netpay= grosspay-taxwithheld;
     
    	System.out.println("netpay: "+netpay);
     
    	}
    }

  5. #5
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: payroll code problem

    Glad to help.

  6. #6
    Member
    Join Date
    Dec 2013
    Posts
    40
    My Mood
    Amazed
    Thanks
    2
    Thanked 11 Times in 11 Posts

    Default Re: payroll code problem

    Oh, thats taken Greg! Only wanted to give him a stroke of a genius. Won't repeat itself.

Similar Threads

  1. [SOLVED] payroll-retrobaseSalary issue
    By frenley in forum What's Wrong With My Code?
    Replies: 14
    Last Post: February 21st, 2014, 01:52 AM
  2. Someone who can help me with my PAYROLL PROGRAM
    By driczdc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 5th, 2013, 05:02 AM
  3. employe payroll
    By daim9996 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 18th, 2013, 08:35 AM
  4. [SOLVED] Please help me with this payroll program
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2011, 06:47 PM
  5. Payroll
    By Kesh486 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 6th, 2010, 06:48 PM