Hi j
I have a question and I am wondering if it can be answered.

the question is, how do you calculate a teaching allowance and nis from the hours of work and rate of pay in java.

with what I understood you want to make simple calculations for a simple work software. am I right?

I use this code:
if you need to get the values from a jLabel you have to convert it in int. this is the code

int sum1 = Integer.parseInt(testlabel1.getText());

do this for all the things you want to calculate

int sumtotal = sum1 + sum2 * sum3 / sum4 ... (and what you want) 
  • and / are optional with what I understood what you're trying to do.

to get the value and print those somewhere you have to convert those to string :

String calculatedsum = Integer.toString(sumtotal);

and use

jlabel1.setText(calculatedsum);

to ser the result in a text

if I am wrong please explain better what you really need.

Edited 1 Year Ago by altjen

what i was trying to say is that a workwer pay has to be calculated by the number of hours work multiplied by the rate of pay plus teaching allowance. all workers receive $325.00 for every hr work and a health surcharge of 33.50 plus NIS plus an income tax of 5% of their gpay are deduction how do you calculated that in java

here is the program, it is the calculation,

double  netsal, incometax = 0;
        double numhrswrk=0, rate_of_pay = 0;
        double gpay, gross_sal, deduction = 0, overtime ;




     System.out.println("What is your id number");                   
            String idnum = readin.next();

            System.out.println("What is your first name");
            String firstname = readin.next();

            System.out.println("What is your last name");
            String lastname = readin.next();

            System.out.println("How many hours have you worked");
            double hrswrk = readin.nextDouble();

            System.out.println("How much is your teaching allowance");
            double teachallow = readin.nextDouble();

            System.out.println("What is the amount of your NIS payment");
            double nis = readin.nextDouble();


            gpay = (numhrswrk * rate_of_pay) + teachallow + 325.00;
            double healthsurcharge = 33.50 + nis;
            incometax =(gpay * 0.5);
            overtime = hrswrk + 325.00;
            netsal = (gpay - deduction);


            System.out.println("payslip");

            System.out.println("the lecturer id number is " + idnum);
            System.out.println("the lecturer name is " + firstname + "\t" +  lastname);
            System.out.println("the hours worked are " + numhrswrk);
            System.out.println("the income tax is " + incometax);
            System.out.println("total deduction is " + deduction);
            System.out.println("the gross pay is $: " +  gpay);
            System.out.println("the netpay is $: " + netsal);


            }

            here is the output

            What is your id number
    R6800G
    What is your first name
    randy
    What is your last name
    george
    How many hours have you worked
    85
    How much is your teaching allowance
    4600
    What is the amount of your NIS payment
    185
    payslip
    the lecturer id number is R6800G
    the lecturer name is randy  george
    the hours worked are 0.0 ( also why i am not seeing the total hours calculated 
    the income tax is 2462.5
    total deduction is 0.0 (why am i not seeing the total deduction here which is supposed to calculated.
    the gross pay is $: 4925.0
    the netpay is $: 4925.0
    BUILD SUCCESSFUL (total time: 44 seconds)

am doing something wrong here, I debug it, look thru it with a fine teeth comb still cyah see what i am missing, which i do know,

hi james

I have since deleted them but I am still getting the hours calculated and the deduction

I have since deleted them and I am still not getting the hours calculated and the deduction calculated at all.

i have added them back again and still getting the same result. the hours is not calculated neither the total deduction. which am supposed to get the required calculation, so it is obvious something is missing, or my calculation is wrong somewhere

Well, yes. Your calcs are a bit of a mess to be honest.
Start by tidying up your variables. For example - the user's input goes into hrswrk, but in the calculation you use numhrswrk (which is still zero).
Declare one variable for each item in the calculation, and just use those.
Then as you go through the calc, print every result as you calculate it, so you can see what you are calculating and how well tht's working.

thank james i get that part to work but now it is only the deduction part am still getting the zero, I tried removing the zero in the variables, and I get a syntax error stating that it might not be initialized.

"I get a syntax error stating that it might not be initialized."

There's the answer. It tells you which variable you forgot to calculate.

hi james

what would I do without you. thank you very much. got it to work

system.out.println("BIG BIG HUGS AND KISSES TO YOU");

hi james
I have another program for you to help me with. will u help me. will post later on tonigh, i have a math exam to sit today so hold some strain.

This question has already been answered. Start a new discussion instead.