|
-
March 26th, 2011, 08:32 AM
#1
Help needed! Calculating weekly pay with if else
Hi, I am really new to programming and am trying to create a program that calculates an employee's weekly pay.
I have worked out the calculations and tested them outside of Java and everything is fine but once I put it all in I ended up with various errors - which I managed to fix (or so I thought) and compiled the program but came back with the wrong figures for "Weekly Income Tax" and the "Take Home Pay".
Weekly Income Tax is based solely upon a calculation for Yearly Income Tax which is meant to be calculated using if statements (and/or boolean expression).
I may be totally wrong ... but if anyone can help it would be appreciated!
Also I need to correct the decimals to 2 decimal places but have no idea how to implement this nor do I know how to add extra lines between the outputs.
Thanks in advance!
PHP Code:
// This program is designed to calculate an employee's pay
import java.util.Scanner;
public class PayCalc
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner (System.in);
Double hoursWorked;
Double dependents;
Double grossPay;
Double adjGross;
Double mediLevy;
Double projectedAnnual;
Double yearTax = 0.00;
Double weekTax;
Double weekAssess;
Double weekTHome;
Double employSuper;
Double employeeSuper = 100.00;
Double childSupport = 50.00;
System.out.print ("Enter the number of hours worked:");
hoursWorked = keyboard.nextDouble();
System.out.print ("Enter the number of dependents:");
dependents = keyboard.nextDouble();
grossPay = (38*15.50)+((hoursWorked-38)*(15.50*1.5));
adjGross = grossPay-employeeSuper;
mediLevy = grossPay*0.015;
projectedAnnual = adjGross*52;
boolean condition = true;
if (projectedAnnual <= 6000) {
yearTax = 0.00;
} else if (projectedAnnual >= 6000) {
yearTax = ((projectedAnnual-6000)*0.15);
} else if (projectedAnnual >= 25000) {
yearTax = (25000-6000)*0.15+((projectedAnnual-25000)*0.30);
} else if (projectedAnnual >= 75000) {
yearTax = (25000-6000)*0.15+(75000-25000)*0.30+((projectedAnnual-75000)*0.40);
} else if (projectedAnnual >= 150000) {
yearTax = (25000-6000)*0.15+(75000-25000)*0.30+(150000-75000)*0.40+((projectedAnnual-150000)*0.45);
}
weekTax = yearTax/52;
weekAssess = grossPay-employeeSuper;
weekTHome = weekAssess-weekTax-mediLevy-childSupport;
childSupport = dependents*50.00;
employeeSuper = 100.00;
employSuper = grossPay*0.09;
System.out.println("Worker's projected yearly gross salary :" +projectedAnnual);
System.out.println("Superannuation Contribution");
System.out.println("Employer contribution :" +employSuper);
System.out.println("Employee contribution :" +employeeSuper);
System.out.println("Worker's weekly assessable income :" +weekAssess);
System.out.println("Weekly income tax :" +weekTax);
System.out.println("Medicare levy :" +mediLevy);
System.out.println("Child Support contribution :" +childSupport);
System.out.println("Take home pay :" +weekTHome);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|