hi james/anyone/stultuske

I am again trying and practicing my java. I am doing this payroll program which include doing methods and array and have no idea where I have gone wrong again

i have debug it but inno me, cant find the error and it is there somewhere anyway here is the program. I am not finish coding am only testing out the program after each block of code just to see how it is running

 double gsalary = 0;
        double rateofpay = 0;
        int usercode = 0;

        if (usercode == 1) {
            gsalary = (575 * hrswrk) + 2500;
        } else if (usercode == 2) {
            gsalary = (325 * hrswrk) + 1250;
        }
        return gsalary;

    }

    public static double calRegwrkrs(double hrswrk, double fsalary) {

        double doubletme = 0, rateofpay = 0, gsalary =0;

        if (hrswrk == 160) {
            gsalary = fsalary;   
        } else if (hrswrk < 160) {
            rateofpay = (fsalary - 160);
            gsalary = hrswrk * rateofpay;
        } else if (hrswrk > 160) {
            doubletme = (hrswrk - 160)* 2 *(fsalary/260);
            gsalary = fsalary + doubletme;
        }
        return gsalary;

    }

    public static double calDeduction( double gsalary){
        double incometax = 0.25, hsurcharge1 = 33.00, hsurcharge2 = 19.20;
        double totaldeduct = 0, totalgsalary;

        incometax = (gsalary * 0.25/100);

        if(gsalary > 499.99) 
        {
            totaldeduct = hsurcharge1 ;
        }
        else if(gsalary > 499.99 && gsalary <5000)
        {
            gsalary = hsurcharge2;
            totalgsalary = (gsalary - 5000)* 0.25 + 33.00;
        }
        return totaldeduct;

    }
    public static double calNsalary(double totaldeduction, double gsalary){
        double  nsalary, totaldeduct = 0;

        nsalary = (gsalary - totaldeduct);

        return nsalary;
    }

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

        char usercode = 0;
        String codeStr = null;
        char code = 0;
        int numofwrkrs = 0;
        int masterdegree = 1, bachelor = 2, empqualicode;

        String empnum = null, reg_wrkrs, lecturer = null, qualification_code;
        int i;
        double hrswrked, rate_of_pay, fixed_salary, totalgross_sal = 0, countreg = 0, count_lecturer = 0;
        double highestgpay = 0, lowestgpay = 0;

        String firstnme[] = new String[numofwrkrs];
        String lastnme[] = new String[numofwrkrs];
        char empcode[] = new char[numofwrkrs];
        double gsalary[] = new double[numofwrkrs];
        double nsalary[] = new double[numofwrkrs];

        for (i = 1; i < numofwrkrs; i++) {
            System.out.println("please enter the employees name ");
            firstnme[i] = userinput.next();

            System.out.println("please enter the employees last name");
            lastnme[i] = userinput.next();

            System.out.println("please enter the employee code");
            empcode[i] = codeStr.charAt(0);
        }

        here is the output which is nothing. I dont know what I have put in or declare wrong and as i said am not finish coding

        run:
BUILD SUCCESSFUL (total time: 0 seconds)
int numofwrkrs = 0;
...
for (i = 1; i < numofwrkrs; i++)

i < numofwrkrs will never return true, so the content of the for block is never executed.

Is that what you mean?

so now it will have to change, thanks

Hey Divinity,
A little word from the unwise. Eclipse provides a wonderful debugging mechanism that will take you through the code. Best to debug issues like this using that if you are stuck. It will help you out in the longer run.
Cheers!!

I have missed more than 9000 shots in my career. I have lost almost 300 games. 26 times, I have been trusted to take the game winning shot and missed. I have failed over and over and over again in my life. And that is why I succeed - Michael Jordan

debugging can show you that that code isn't executed, it doesn't explicitly state why it isn't executed.
unfortunately people start to fast with relying on IDE's, while this snippet is actually a perfect example of what you don't need an IDE for and should be able to solve on sight.

In my opinion the Eclipse debugger has a very steep learning curve, and is far too difficult for someone who hasn't started learning about threads yet. For a beginner I think it's far better to stick to what they already know, and put in lots of System.out.println calls.

thanks you guys, james, stultuske and newcode310
thank you all for taking the time to explain

debugging can show you that that code isn't executed

I think that this is enough to know that first. Then the developer can have a starting point to debug himself. I feel using an IDE is better than asking someone else to point the error for you. In this case, you have solved this error for divinity02. I also agree that using System.out.println is better. But my main point is that a developer should exhaust all options before asking for help. Alteast that's my thought process.

newcoder, you are right: debugging for yourself is better. but, when it comes to starting developers/programmers, they should not be using an IDE just yet, even though every teacher/professor seems to have the idea "let's make 'm use an heavyweight IDE from day one, it'll make them work more professionally".

This is about the biggest mistake they can make: not only do they have no idea of what the IDE is doing in the background (or why), but they are not learning to program (which means writing code, knowing how to find their way through documentation to know what they want), they merely learn how to use (and rely on) one IDE.

Beginning developers shouldn't bother with an IDE, or its debugging tools, they should actually learn how to write code, without some auto-completion and a few buttons do all the work. Always "fun" to see people who learned to develop like that, start at their first job, only to discover their employer makes them use a different IDE they're used to.

I definitely agree with you on the IDE part.

hi james, stultuske and newcode310
can u download the eclipse
I think i tried to down it but something went wrong, I dont know if it clash with the netbeans as netbeans is the one that I am using.

will there any problems with netbeans if i download the eclipse

no, it won't, but my opinion remains the same: don't use an IDE until you know the language better.

Why download Eclipse when you already have NetBeans? Whay do you think Eclipse can possibly do for you at this stage?
Eclipse won't give you anything more than Netbeans for ordinary Java development, but it will confuse you and waste your time learning how to use a second IDE.

You have so many problems already with the simplest Java code. In my opinion it's crazy to add an IDE's learning curve to your existing struggle. I would advise you to delete your IDE and use a simple editor and the JDK tools to learn how to code Java first.

ok james and stultuske

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.