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 3 of 3

Thread: Payroll code runs fine, but if I input hours > 40, the cost to employer calculation goes wrong...

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

    Default Payroll code runs fine, but if I input hours > 40, the cost to employer calculation goes wrong...

    --- Update ---

    [/COLOR]Oh gosh, I think I fixed the first error, but now I'm receiving another error in my Net Pay print statement at the end.
    Here is what I'm supposed to receive:
    Net Pay: 599.86
    Here is my sample run:
    run-single:
    Enter hourly rate in dollars and cents --> 27.16
    Enter number of hours and tenths worked --> 37.9

    PAYROLL REPORT
    Rate: 27.16
    Hours: 37.9

    Gross Pay: 1029.36
    Federal Tax: 257.34
    State Tax: 93.41
    FICA: 78.75
    Net Pay: 771.86

    Employer's FICA contribution: 78.75
    Employer's UEI and DI contribution: 20.59
    Cost to Employer: 1128.70

    Enter hourly rate in dollars and cents -->
    Here is my updated code:
    package assignmentproject1;
    /* CHANGE (FINAL) VAR NAMES, SCAN & VERIFY, 
    ORGANIZE AND PUT FORMULAS ON BOTTOM, ORGANIZE VAR @ TOP, */
    import java.util.*;
    public class Project1 
    {
     
        public static void main (String[] args) 
        {
     
            Scanner stdin = new Scanner (System.in);
     
     
            final int OVERTIMEHOURS = 40;           
            final double FEDTAX = 0.25, CALITAX = 0.09075, SS_MEDI_FICA = 0.0765,
                    UEIDI = 0.02, OVERTIMEMULTIPLIER = 1.5;
            double  fedtax, ss_medi_fica, grossPay, rate, totalcost_to_Employer, 
                    calitax, netPay, hours, ueidi, employerFICA;
            boolean overtime = false;
     
     
            //Inputs rate and hours, then calculates the gross pay.
            System.out.print ("Enter hourly rate in dollars and cents --> ");
            rate =  stdin.nextDouble ();
     
     
            while (rate > 0)
            {           
                System.out.print ("Enter number of hours and tenths worked --> ");
                hours = stdin.nextDouble ();  
     
                System.out.println ();// LINE SPACER
     
                System.out.println ("               PAYROLL REPORT");
     
                System.out.printf ("Rate:%38.2f \n",rate);
     
                System.out.printf ("Hours:%37.1f \n",hours);
     
     
     
                grossPay = rate * hours; //calculates gross pay.
                fedtax = grossPay * FEDTAX; //calculates federal tax.       
                calitax = grossPay * CALITAX; //calculates state (CA) tax.
                ss_medi_fica = grossPay * SS_MEDI_FICA; //employee pays for FICA.
                ueidi = grossPay * UEIDI;        
                employerFICA = grossPay * SS_MEDI_FICA; //employer pays for FICA.            
                netPay = grossPay -  (fedtax + CALITAX + SS_MEDI_FICA);
                totalcost_to_Employer = grossPay + employerFICA 
                    + ueidi;
     
                //CHECKS CONDITION        
                System.out.println ();// LINE SPACER
     
                if (hours > 40)
                { 
                    overtime = true;
                    grossPay = rate * OVERTIMEHOURS + (hours - OVERTIMEHOURS) 
                            * (rate * OVERTIMEMULTIPLIER);
                    fedtax = grossPay * FEDTAX; //calculates federal tax.       
                    calitax = grossPay * CALITAX; //calculates state (CA) tax.
                    ss_medi_fica = grossPay * SS_MEDI_FICA; //employee pays for FICA.
                    ueidi = grossPay * UEIDI;        
                    employerFICA = grossPay * SS_MEDI_FICA; //employer pays for FICA.            
                    netPay = grossPay - (fedtax + CALITAX + SS_MEDI_FICA);
                    totalcost_to_Employer = grossPay + employerFICA 
                    + ueidi;
                    System.out.printf ("Gross Pay: %32.2f ", grossPay);   
                    System.out.print ("  includes overtime\n");
                }
                else 
                {
                    grossPay = rate * hours;
                    System.out.printf ("Gross Pay: %32.2f \n", grossPay);
     
                }
                System.out.printf ("Federal Tax: %30.2f \n", fedtax);
     
                System.out.printf ("State Tax: %32.2f \n", calitax);
     
                System.out.printf ("FICA: %37.2f \n", ss_medi_fica);
     
                System.out.printf ("Net Pay: %34.2f \n", netPay);
     
                System.out.println ();
     
                System.out.printf ("Employer's FICA contribution: %13.2f \n", 
                    employerFICA);
     
                System.out.printf ("Employer's UEI and DI contribution: %7.2f \n",
                    ueidi);
     
                System.out.printf ("Cost to Employer: %25.2f \n", 
                    totalcost_to_Employer);    
     
                System.out.println();//line spacer
     
                System.out.print ("Enter hourly rate in dollars and cents --> ");
                rate =  stdin.nextDouble ();    
     
                overtime = false;/*have to reset overtime, 
                                    so it doesn't apply to regular hours*/
            }//end of while loop
     
        }//end main
     
    }//end class


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: Payroll code runs fine, but if I input hours > 40, the cost to employer calculation goes wrong...

    is it because you computed it wrong?
    it seems that there are no errors in your code, right?

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    24
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Payroll code runs fine, but if I input hours > 40, the cost to employer calculation goes wrong...

    Quote Originally Posted by dicdic View Post
    is it because you computed it wrong?
    it seems that there are no errors in your code, right?
    Yeah, that's got to be a typo what the professor typed lol... it's weird because it's based on our first project.. and I got everything all of the specs right, and the output that the professor wanted too... oh well, not worrying about it anymore =\

Similar Threads

  1. [SOLVED] payroll code problem
    By JJAus in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 22nd, 2014, 08:39 AM
  2. Analyzing Input Files, Code Runs Forever
    By jwr in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 23rd, 2013, 05:24 PM
  3. GPA Calculation Program using an input file
    By ddk1992 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 6th, 2011, 06:28 AM
  4. code issue, should be silple been working on it for four hours
    By Custermd in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 30th, 2011, 01:19 PM
  5. HELP! Gui is running fine, don't know exactly how to code.
    By cc11rocks in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 12th, 2011, 02:12 PM