This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2016/1/18

how to calculate the income tax

divinity divinity

2016/1/18

#
hi all I am doing this program. I manage to get everything to be working correctly except for the income tax part. what do i have to do in order to calculate the income tax for the output to show how much income tax on the user payslip. i tried everything but i am still getting a zero output. tell me what to do and how to go about gettin the calculation correctly otherwise everything else is working properly . here is my code
 final double health_surcharge = 33.50;
        
        double hrs, hrswrk, gsalary = 0, NIS,nsalary=0, rate_of_pay = 0,totaldeduct = 0, incometax, teaching_allow;
        double overtime = 0, income_tax = 0, total_tax;
        
        
        System.out.println("please enter the lecturer id number");
        String lecturerID = userinput.nextLine();
        
        System.out.println("please enter the lecturer first name");
        String firstname = userinput.next();
        
        System.out.println("please enter the lecturer last name");
        String lastname = userinput.next();
        
        System.out.println("please enter the number of hours work");
        hrswrk = userinput.nextDouble();
        
        System.out.println("please enter the teaching allowance");
        teaching_allow = userinput.nextDouble();
        
        System.out.println("please enter your NIS contribution");
        NIS = userinput.nextDouble();
        
        
        hrs = (hrswrk * rate_of_pay) + teaching_allow;
        hrs = (overtime * rate_of_pay);
        total_tax = (health_surcharge + NIS) + (gsalary * 0.5);
        total_tax = (gsalary * 0.5);
        gsalary = (gsalary + teaching_allow);
        totaldeduct =(NIS + health_surcharge);
        nsalary = (gsalary - totaldeduct);
        
        
        System.out.println("the lecturer id is "+ lecturerID);
        System.out.println("the lecturer first and last name is "+ firstname +lastname);
        System.out.println("the hours worked is "+ hrswrk);
        System.out.println("the income tax is "+income_tax);
        System.out.println("the total deduction is "+totaldeduct);
        System.out.println("the gross salary is "+gsalary);
        System.out.println("the net salary is "+nsalary);
        
danpost danpost

2016/1/18

#
From what I can tell, no rate of pay is being input and 'gsalary' is being used with a value of zero before its value is calculated. Also, you have two sets of lines where the second one overrides the first (lines 26 and 27 and lines 28 and 29). The value calculated in the first lines of each set is being replaced by the values calculated in the second lines of each set.
You need to login to post a reply.