Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Problem (Payroll System)

Options
  • 28-04-2005 11:21am
    #1
    Closed Accounts Posts: 873 ✭✭✭


    Iv been working on a small program the last few days in java, we use the tony mullins screen and keyboard classes(www.tonymullins.com), as you can see im fairly hopeless at java but was hoping you guys might be able to pick up on some of my errors. In total i think i have about 15.
    class payroll{
    public static void main(String[]args){

    double workers,salary,overtime,netpay,tax,gross,rate;

    Screen.message("Please enter the number of People who have worked this week:");
    Screen.newline();
    workers = Keyboard.readInt();

    for(int j = 0; j < workers.length; j = j + 1){

    Screen.message("Please enter your yearly salary:");
    Screen.newline();
    salary = Keyboard.readDouble();
    Screen.newline();

    Screen.message("How many hours extra hours have you worked this week:");
    Screen.newline();
    overtime = Keyboard.readDouble();
    Screen.newline();

    Screen.message("What is your overtime rate of pay:");
    Screen.newline();
    rate = Keyboard.readDouble();
    Screen.newline();

    gross = grosspay(double salary, double overtime, double rate);
    tax = tax(double salary);
    netpay = netpay(double tax, double gross)


    Screen.message("Your gross pay is:");
    Screen.newline();
    Screen.writeDouble(gross);
    Screen.newline();


    Screen.message("Your tax is:");
    Screen.newline();
    Screen.writeDouble(tax);
    Screen.newline();


    Screen.message("Your net pay is:");
    Screen.newline();
    Screen.writeDouble(netpay);
    Screen.newline();


    static int grosspay(double salary, double overtime, double rate){

    double gross;
    gross = (overtime*rate)+(salary/52);
    return(gross);

    }

    static double tax(double salary){

    if(salary < 17000)
    tax = 0;

    if(salary > 17000 & < 35000)
    tax = 22;

    if(salary > 42000)
    tax = 42;

    return(tax);

    }

    static double netpay(double tax, double gross){

    double socialcost

    Screen.message("Are you a member of the social club? Yes = 1, No = 0");
    Screen.newline();
    social = Keyboard.readInt();
    Screen.newline();
    if(social = 1)
    socialcost = 5.50;
    if(socail = 0)
    socialcost = 0;

    netpay = (gross/100)*(tax - gross)- socialcost

    return(netpay);

    }


Comments

  • Registered Users Posts: 705 ✭✭✭CTU_Agent


    tony mullins....He taut me Computer studies and JAVA...Man It was difficult... I know it doesnt help much with your problem but it brings the memories flooding back looking at that screen and keyboard code!!


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    neon_glows wrote:
    Iv been working on a small program the last few days in java, we use the tony mullins screen and keyboard classes(www.tonymullins.com), as you can see im fairly hopeless at java but was hoping you guys might be able to pick up on some of my errors. In total i think i have about 15.

    You've alot of spelling errors in there, if you look at the bottom you say "socail" instead of "social", and btw social is not declared anywhere.
     double socialcost // there's no semi-colon
     netpay = (gross/100)*(tax - gross)- socialcost // no semi-colon
    


  • Registered Users Posts: 1,184 ✭✭✭causal


    static [B]int[/B] grosspay(double salary, double overtime, double rate){
    [B]double gross;[/B]
    gross = (overtime*rate)+(salary/52);
    [B]return(gross)[/B];
    }
    
    You are returning a double, but the method definition is for an int.
    afair a narrowing conversion like this is thrown out by the compiler.
    Also you already have an instance variable called 'gross'; while it's ok to have another with the same type and name within the scope of this method it can cause confusion.

    Practice interpreting the compiler errors - it's a great skill to have (unless you can code error free ;) )

    causal


  • Registered Users Posts: 6,240 ✭✭✭hussey


    Ok lets start at start
    No closing brackets for either for loop and main method
    for(int j = 0; j < workers.length; j = j + 1){ should be
    for(int j = 0; j < workers; j = j + 1){

    gross = grosspay(double salary, double overtime, double rate);
    should be
    gross = grosspay(salary, overtime, rate); - same with rest of methods

    grosspay should return a double

    in method tax
    if(salary > 17000 & < 35000)
    this makes no sence - should it be if( (salary > 17000) && (salary < 35000))

    in method netpay
    forgot ; after socialcost and netpay =
    also you never decalred netpay/social as a double
    should read
    if(social == 1)


  • Closed Accounts Posts: 873 ✭✭✭neon_glows


    sound guys i finally got it working, thanks a million, your all so cool


  • Advertisement
Advertisement