Weekly Pay Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dexterdreads
    New Member
    • May 2007
    • 5

    Weekly Pay Program

    [/QUOTE][/HTML]How do I get the variable "nPay" to give me a result?


    [QUOTE]
    import java.util.Scann er;

    public class WeeklyPay1
    {


    public static void main(String[] a)
    {
    String name; //Employee's name
    String input; //Holds additional kb info
    char married; //Married? y or n
    char health; //Healthcare? y or n
    double hours; //Hours worked by employee
    double gPay; //Gross pay
    double nDep; //Number of Dependents
    double TaxPay; //Income that is taxable
    double Taxes; //Holds tax rate for taxable pay
    final double marDed= 150; //Standard Deductions for married
    final double sDed = 75; //Standard Deductions for single
    final double mMed=100; //Medical deductions for married
    final double sMed=60; //Medical deductions for single
    double nPay; //Employees Net Pay


    Payroll1 getpaid = new Payroll1();

    Scanner kb = new Scanner(System. in);


    //Get the Employee's marital status
    System.out.prin t("Are you Married? Y or N: ");
    input = kb.nextLine();
    married = input.charAt(0) ;

    //Do you have Healthcare?
    System.out.prin t("Do you have Healthcare: Y or N: ");
    input = kb.nextLine();
    health = input.charAt(0) ;

    //Get Employee's name
    System.out.prin t("Enter your name: ");
    name = kb.nextLine();

    //Get Employee's Pay Rate
    System.out.prin t("Enter pay rate: ");
    rate = kb.nextDouble() ;


    //Get Employee's hours worked
    System.out.prin t("Enter the number of hours you worked: ");
    hours = kb.nextDouble() ;


    //Get Employee's dependents
    System.out.prin t("How many dependents do you have: ");
    nDep = kb.nextDouble() ;

    //Store the data
    getpaid.setPayR ate(rate);
    getpaid.setHrsW orked(hours);
    getpaid.setDepe ndents(nDep);


    //Determine if married, and determine tax bracket
    if(married == 'Y' || married == 'y')
    {
    //Calculate taxable pay
    TaxPay = getpaid.getGros sPay()- marDed - (70 * getpaid.getDepe ndents());

    if (health == 'Y' || health == 'y')

    TaxPay = TaxPay - 100;

    if(TaxPay > 800)

    Taxes = (TaxPay - 800) * .35 + (800 - 500) * .25 + (500 - 200) * .15 + 200 * .10;

    else if (TaxPay > 500)

    Taxes = (TaxPay -500) * .25 + (500-200) * .15 + 200 * .10;

    else if (TaxPay > 200)

    Taxes = (TaxPay -200) * .15 + 200 * .10;

    else

    Taxes = (TaxPay * .10);
    }

    else
    {
    TaxPay = getpaid.getGros sPay() - sDed - (70 * getpaid.getDepe ndents());


    if(health == 'N' || health == 'n')

    TaxPay -= 60;

    if (TaxPay > 400)

    Taxes = (TaxPay - 400) * .35 + (400 - 250) * .25 + (250 -100) * .15 + 100*.10;

    else if (TaxPay > 250)

    Taxes = (TaxPay - 250) * .25 + (250 - 100) * .15 + 100 * .10;

    else if (TaxPay > 100)

    Taxes = (TaxPay - 100) * .15 + 100 * .10;

    else

    Taxes = TaxPay * .10;
    }

    nPay = getpaid.getGros sPay() - mMed; // - Taxes;
    System.out.prin tln("Net Pay " + nPay);
    }
    }
    }
    }
  • nomad
    Recognized Expert Contributor
    • Mar 2007
    • 664

    #2
    It seem you have several errors in your project

    What does rate do?
    I don't see a data type for it. it should be a double

    These have no data types. These method are undefined for the type WeeklyPay
    //Store the data
    getpaid.setPayR ate(rate);
    getpaid.setHrsW orked(hours);
    getpaid.setDepe ndents(nDep);

    Payroll1 getpaid = new Payroll1(); should be unless you have another class
    WeeklyPay getpaid = new WeeklyPay();

    Last thing. your cal. might be wrong, remember any thing in Bracket are done first... Review on how do do cal and in what order they are complied at.
    nomad

    Comment

    Working...