hi

Iam doing a payroll system for a compny where I have to implement a program to calculate workers pay. for commission paid workers, hourly paid workers and fixed monthly paid worker.

i have done the codes but something is wrong somewhere between the codes. cant tell if it is my calculations is missing a line of calculation or i have missout a code because the output it not giving me what the program should. here is my code and can tell me where and what I am missing here. been trying for days to figure what i didnt add it, whether it is the missing code or missing calculation

{   
        double total_deduction;

        total_deduction = gross_pay - deduction;

        return total_deduction;   
    }

    public static double calGrossH(double hours_worked, double pay_rate)

    {
        double extra_time, over_time = 0;

        extra_time = hours_worked - 40;
        over_time = (pay_rate * 1.5) * extra_time;
        over_time = (40 * pay_rate)+ over_time;

        return extra_time;
    }

    public static double calGrossC(double fixed_salary, double commission)
    {
        double  ans, comm_incent, totalsales = 0;

        totalsales = totalsales * 5 / 100;
        comm_incent = fixed_salary + commission;

        return totalsales;    
    }

    public static double calDeductions(double grosspay, double taxes)
    {
        double gross_pay;

        gross_pay = grosspay - taxes;

        return gross_pay;   
    }
    public static double calNetpay(double grosspay, double total_deductions)  
    {
        double netpay;

        netpay = grosspay - total_deductions;

        return netpay;
    }

the part above is the method
the part below is the code 

    public static void main(String[] args) {
        Scanner read = new Scanner (System.in);

        String emp_firstname = null, emp_surname = null, emp_typecode = null,payslip, report;
        int i,emp_idnum = 0, ans, sum, rate = 0, hours = 0, taxfree_allow = 0, taxes = 0;
        int highest = 0,lowest = 0,pay, numofemp = 0, comm_workers = 0, hourlypaid_workers = 0, monthly_paidworkers = 0;
        int count_pos = 0,  count_neg = 0, num = 0, highest_paid = 0, lowest_paid = 0;
        double  fixed_salary = 0, comm_incent = 0,commission = 0, grosspay = 0,   deductions = 0, total_deductions = 0, extra_time, net_pay = 0, gross_pay = 0;
        double totalsales = 0;
        char f,c, h, typecode = 0;
        int pay_rate = 0, hours_worked = 0;


        for( i= 0; i<=3; i++)
        {


                 System.out.println("please enter the number of employees to be processed");
                 numofemp = read.nextInt();

                 System.out.println("please enter employee id number");
                 emp_idnum = read.nextInt();

                 System.out.println("please enter employee first name");
                 emp_firstname = read.next();

                 System.out.println("please enter the employee surname");
                 emp_surname = read.next();

                 System.out.println("please enter the employee typecode");
                 emp_typecode = read.next();


                 taxfree_allow = 5000;
                 taxes = 025;
                 deductions = (taxfree_allow * 25 / 100);
                 comm_incent = totalsales + .05;


                 if(hours_worked == 40 * 120)


                  total_deductions = calGrossF(gross_pay, deductions);
                   extra_time = calGrossH(hours_worked, pay_rate);
                  totalsales = calGrossC(fixed_salary, commission);
                  gross_pay = calDeductions(grosspay, taxes);
                  net_pay = calNetpay(grosspay, total_deductions);


                 {
                   gross_pay = hours_worked * pay_rate;
                   net_pay = gross_pay - total_deductions;  
                 }

                 System.out.println("payslip");
                 payslip = read.nextLine();

                 System.out.println("the employee id number is " + emp_idnum);
                 System.out.println("the employees first name and surname is " + emp_firstname + emp_surname);
                 System.out.println("the employee type code is " + emp_typecode);
                 System.out.println("the employees gross pay is " + gross_pay);
                 System.out.println("the total deduction is " + total_deductions);
                 System.out.println("the netpay is " + net_pay);

                 System.out.println("report");
                 report = read.nextLine();

                 System.out.println("the total number of processed employess is " + numofemp);
                 System.out.println("the number of commission paid worker is " + comm_workers );
                 System.out.println("the number of hourly paid workers is " + hourlypaid_workers);
                 System.out.println("the number of monthly paid workers is " + monthly_paidworkers);
                 System.out.println("the total culmative figure of gross pay,deductions and net pay of all employees are " + gross_pay + net_pay + deductions);

                 if(num < lowest)
                {
                  lowest = num;
                }
                 if(num > highest)
                {
                  highest = num;
                }
                 if(num > 0)
                {
                 count_pos++; 
                }
                 if(num >0)
                {
                 count_neg++;
                 }
                 System.out.println("the name and value of the highest paid employee is " + highest_paid);
                 System.out.println("the name and value of the lowest paid employee is " + lowest_paid);
         }   }
and this part is the output
run:
please enter the number of employees to be processed
31
please enter employee id number
3669
please enter employee first name
ken
please enter the employee surname
kenton
please enter the employee typecode
c
payslip
the employee id number is 3669
the employees first name and surname is kenkenton
the employee type code is c
the employees gross pay is 0.0
the total deduction is 0.0
the netpay is 0.0
report

the total number of processed employess is 31
the number of commission paid worker is 0
the number of hourly paid workers is 0
the number of monthly paid workers is 0
the total culmative figure of gross pay,deductions and net pay of all employees are 0.00.01250.0
the name and value of the highest paid employee is 0
the name and value of the lowest paid employee is 0
please enter the number of employees to be processed
30
please enter employee id number
5447
please enter employee first name
kenny
please enter the employee surname
lennison
please enter the employee typecode
h
payslip
the employee id number is 5447
the employees first name and surname is kennylennison
the employee type code is h
the employees gross pay is 0.0
the total deduction is 0.0
the netpay is 0.0
report

the total number of processed employess is 30
the number of commission paid worker is 0
the number of hourly paid workers is 0
the number of monthly paid workers is 0
the total culmative figure of gross pay,deductions and net pay of all employees are 0.00.01250.0
the name and value of the highest paid employee is 0
the name and value of the lowest paid employee is 0
please enter the number of employees to be processed
95
please enter employee id number
6335
please enter employee first name
jamie
please enter the employee surname
leston
please enter the employee typecode
f
payslip
the employee id number is 6335
the employees first name and surname is jamieleston
the employee type code is f
the employees gross pay is 0.0
the total deduction is 0.0
the netpay is 0.0
report

the total number of processed employess is 95
the number of commission paid worker is 0
the number of hourly paid workers is 0
the number of monthly paid workers is 0
the total culmative figure of gross pay,deductions and net pay of all employees are 0.00.01250.0
the name and value of the highest paid employee is 0
the name and value of the lowest paid employee is 0
please enter the number of employees to be processed
64
please enter employee id number
9669
please enter employee first name
felix
please enter the employee surname
williams
please enter the employee typecode
h
payslip
the employee id number is 9669
the employees first name and surname is felixwilliams
the employee type code is h
the employees gross pay is 0.0
the total deduction is 0.0
the netpay is 0.0
report

the total number of processed employess is 64 (post 1)
the number of commission paid worker is 0 - supposed to output no. of comm workers (post 2
the number of hourly paid workers is 0 - supposed to output no. of hourly paid workers (post 3)
the number of monthly paid workers is 0 - supposed to output no. of fixed monthly paid workers (post 4)
the total culmative figure of gross pay,deductions and net pay of all employees are 0.00.01250.0 - supposed to calculated the netpay, deduction and gross pay of all employees (post 5)
the name and value of the highest paid employee is 0 - supposed to print out the highest paid and value worker (post 6
the name and value of the lowest paid employee is 0 - supposted to print out the lowest paid ad value worker (post 7)
BUILD SUCCESSFUL (total time: 1 minute 22 seconds)

it doesnt do it. this is what I am getting. help

Well you never seem to set the hours_worked to anything other than 0.

Also, keep in mind that when you write

if(hours_worked == 40 * 120)
    total_deductions = calGrossF(gross_pay, deductions);
    extra_time = calGrossH(hours_worked, pay_rate);
    totalsales = calGrossC(fixed_salary, commission);

It will be interpreted as

if(hours_worked == 40 * 120){
    total_deductions = calGrossF(gross_pay, deductions);
}
extra_time = calGrossH(hours_worked, pay_rate);
totalsales = calGrossC(fixed_salary, commission);

So extra_time will always be calculated even when hours_worked is not equal to 40*120. Which is never the case since hours_worked is set to 0 and never changes. I assume you'll want the user to set the hours before the calculations start and go from there.

do have to set the hours worked to another number other than 0 or can left it as is because i have change the hours worked to not equal to 40 *120 and still getting the same result except for the netpay is saying 1250.0 for all so i am guessing something is still wrong with the calculation but cant see it

There are a few variables that never get any sensible values (eg hours worked, pay rate). It looks like you may have missed the part of the assignment where you were supposed to get those values?

Edited 1 Year Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.