Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all: I have been practicing with this payroll program for the longest while now and for the life of me, i just cant seem to get it to give me the correct output.

I am not getting the gross pay, netpay, deduction to give the the correct output, it has been outputting zero.

and it also need to output the employees that received the highest and lowest salaries. I am not getting that also.

at one time i was getting an arrayindexoutofbound error for one of the label where it says to output the employee qualification code. I had it in an array but i have since removed it from the array and now it is stuck after prompting for the employee fixed salary. can someone help me with it I mean explain to me where and what i am missing here and what i am not doing.

the program is also to generate the total payroll for all employees and that and all i am not getting. so here is my codes that i have used

What I have tried:

Java
public static double calGrossLecturer(double hrswrk, double payrate)
    {
        int i=0;
        
        double grosspay;
        
        grosspay = (hrswrk * 575) + 2500.00;
        
        return grosspay;
    }
    public static double calGrossRWorker(double hrswrk, double payrate)
    {
        int i=0;
        
        double grosspay;
        
        grosspay = (hrswrk * 325) + 1250.00;
        
        return grosspay;
    }
    public static double calDeductions(double NIS, double healthsurcharge)
    {
        int i=0;
        double deductions;
        
        deductions = (NIS + healthsurcharge);
        
        return deductions;
    }
    public static double calNetpay(double grosspay, double deductions)
    {
        int i=0;
        
        double netpay;
        
        netpay = (grosspay - deductions);
        
        return netpay;
    }
  
    public static void main(String[] args) 
    {
        Scanner userinput = new Scanner(System.in);
        
        int arrar[]=new int[8];
        
        double  fixedsalary=0,hrlyrate=0,
                NIS=0,healthsurcharge=0, 
                gp,  np, hrswrk, personal_allow=0,
                payrate=0, max=0, min=0;
                
        int i=0;
        char qcode = 'r';
        
        char emp_unique_cde[]= new char[2];
        String emp_fullname[] = new String[8];
        String emp_lastname[] = new String[8];
        double grosspay[] = new double[8];
        double deductions[]= new double[8];
        double netpay[]= new double[8];
        double salaries[] = new double[8];
        int process_emp[] = new int[8];
        int num_emp[] = new int[8];
        double totalPayroll[] = new double[8];
        
        
        System.out.println("How many employetes that are being processed");
        process_emp[i] = userinput.nextInt();
        
        System.out.println("Please enter the employee ID number");
        String emp_IDnum = userinput.next();
        
        System.out.println("Please enter the employee full name");
        emp_fullname[i] = userinput.next();
        
        System.out.println("Please enter the employee last name");
        emp_lastname[i] = userinput.next();
        
        System.out.println("Please enter the employee departmet working in");
        String department = userinput.next();
        
        System.out.println("Please enter the employee hours of work");
        hrswrk = userinput.nextDouble();
        
        System.out.println("Please enter the employee  unique ID  code");
        emp_unique_cde[i] = userinput.next().charAt(0);
        
        if(emp_unique_cde[i] == 'r' ||emp_unique_cde[i] =='R'|| emp_unique_cde[i] == 'l' || emp_unique_cde[i] == 'L')
        {
            System.out.println("please enter your employee qualification code");
            qcode = userinput.next().charAt(0);
            
            if(qcode == 1)
            {
                gp = calGrossLecturer(hrswrk, payrate);
            }
            else if(qcode == 2)
            {
                gp = calGrossRWorker(hrswrk, payrate);
            }
            
            System.out.println("Please enter the employee fixed salary");
            fixedsalary = userinput.nextDouble();
            
            if(hrswrk == 160)
            {
                gp = (fixedsalary);
            }
            else if(hrswrk < 160)
            {
                hrlyrate = (fixedsalary / 160);
                gp = (hrlyrate * hrswrk);
            }
            else
            {
                gp = (fixedsalary) + (hrswrk - 160) * 2 * hrlyrate;
            }
            if(gp < 5000)
            {
                deductions[i] = calDeductions(NIS, healthsurcharge);
            }
            else
            {
                gp = (grosspay[i] - 5000) * 0.25 + 33 + 19.20;
                netpay[i] = calNetpay(grosspay[i], deductions[i]);
            }
           
           while(totalPayroll[i] < salaries[i])
            {
                System.out.printf("Enter employee monthly salary %d: ", totalPayroll[i]);
            }
            
            while(totalPayroll[i] < num_emp[i])
            {
                
                if(totalPayroll[i] == num_emp[i])//if the totalpayroll is equal to the amount of employees on the payroll
                {
                    personal_allow = personal_allow * 0.15;
                    totalPayroll[i] = (hrswrk + fixedsalary + grosspay[i] + hrlyrate) + netpay[i] + personal_allow + 160 * 2 * payrate;
                }
               
            }
               max = salaries[0];
               int freq = 1;
               
                for(i = 0; i < salaries.length; i++)
                {
                    salaries[i] = userinput.nextDouble();
                    
                    if(salaries[i] > max)
                    {
                        freq = 1;
                        
                        max = salaries[i];
                    }
                    else if(salaries[i] == max)
                    {
                        max = salaries[i];
                    }
                }
                  max = salaries[0];
               
                  
                  freq = 1;
               
                for(i = 0; i < salaries.length; i++)
                {
                    salaries[i] = userinput.nextDouble();
                    
                    if(salaries[i] > min)
                    {
                        freq = 1;
                        
                        min = salaries[i];
                    }
                    else if(salaries[i] == min)
                    {
                        min = salaries[i];
                    }
                }
                
                System.out.println("The employees qualification code is: "+qcode);
                System.out.println("The employee unique code is: "+emp_unique_cde[i]);
                System.out.println("The employee number is: "+ emp_IDnum);
                System.out.println("The employee full and last name is: "+emp_fullname[i]+" "+emp_lastname[i]);
                System.out.println("The department the employee working in is: "+department);
                System.out.println("The employee hours of work is: "+hrswrk);
                System.out.println("The total deduction is: "+deductions[i]);
                System.out.println("The gross pay is: "+grosspay[i]);
                System.out.println("The netpay is: "+netpay[i]);
                 
                System.out.println("\n************Report********************\n");
                 
                System.out.println("The number of process employees are: "+process_emp[i]);
                System.out.println("The total grosspay for all employees are: "+totalPayroll[i]);
                System.out.println(emp_fullname[i]+" "+emp_lastname[i]+ " is the highest paid employee who received: "+ " the amount of $: "+max);
                System.out.println(emp_fullname[i]+" "+emp_lastname[i]+ " is the lowest paid employee who received: "+ " the amount of $: "+min);
Posted
Updated 27-Jun-16 18:20pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Jun-16 23:39pm    
Sorry, this is not a question.
All the help you need is one magic word: the debugger.
—SA
Richard MacCutchan 28-Jun-16 3:58am    
Do not use float or double for financial values, use integer or decimal.

1 solution

You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop performing as you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Use the debugger to narrow the bug research. If you find a particular place that go wrong and you don't understand why, come back and explain the particular problem.

you can remove
C++
int i=0;

from the first 4 routines since it is unused.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900