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

2016/2/25

what am i missing here

divinity divinity

2016/2/25

#
hi i am practicing this program here and i am outputting zero. trying my best where is the error here is the code
double fed_tax = 0, state_tax = 0,  hrswrk, payrate=0, gross_salary = 0;
        double hrlyrate=0;
        
        System.out.println("hi please enter your first name");
        String firstname = userinput.next();
        
        System.out.println("hi please enter your last name");
        String lastname = userinput.next();
        
        System.out.println("hi please enter the number of hours work");
        hrswrk = userinput.nextDouble();
        
        
        double hrs = (hrlyrate * hrswrk);
        hrs = (payrate * hrswrk);
        gross_salary = (fed_tax * 0.20) + gross_salary;
        gross_salary = (state_tax  * 0.9) + gross_salary;
        double total_deduction = (fed_tax + state_tax);
        double net_salary = (gross_salary - total_deduction);
        
        System.out.println("the employee name is "+firstname+lastname);
        System.out.println("the total deduction is "+total_deduction);
        System.out.println("the gross pay is "+gross_salary);
        System.out.println("the net salary is "+net_salary);
        
danpost danpost

2016/2/25

#
The only numeric variable whose value is not zero after line 11 is 'hrswrk' -- 'hrlyrate' is still zero so line 14 sets 'hrs' to zero; 'payrate' is still zero so line 15 sets 'hrs' to zero (again); 'fed_tax' and 'gross_salary' are still both zero so line 16 sets 'gross_salary' to zero; 'gross_salary' and 'state_tax' are both still zero so line 17 sets 'gross_salary' to zero (again); 'fed_tax' and 'state_tax' are still both zero so line 18 sets 'total_deduction' to zero; finally, 'gross_salary' and 'total_deduction' still remain set to zero so line 19 set ''net_salary' to zero. I hope you can see why your output is still zero.
divinity divinity

2016/2/26

#
hi danpost i removed the zero from fed_tax, state_tax, gross_salary, payrate and hrly rate and i get syntax errors, how do i correct this
danpost danpost

2016/2/26

#
divinity wrote...
hi danpost i removed the zero from fed_tax, state_tax, gross_salary, payrate and hrly rate and i get syntax errors, how do i correct this
The problem is not that you are setting those fields to zero when you declare the variables; and by removing the assignment to zero, you are not really altering anything -- as the default value for new double type variables is zero. The problem is that these variables need to be assigned some non-zero values somewhere along the way. I would think that there is a table or database that associates a name with a specific 'hrlyrate' value. Also, does not 'payrate' and 'hrlyrate' really mean the same thing (should not one of the two be removed)?
You need to login to post a reply.