Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Help me with beginner coding

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help me with beginner coding

    Write a method named pay that accepts a real number for a TA's salary and an integer for the number of hours the TA worked this week, and returns how much money to pay the TA. For example, the call pay(5.50, 6) should return 33.0.

    The TA should receive "overtime" pay of 1 ½ normal salary for any hours above 8. For example, the call pay(4.00, 11) should return (4.00 * 8) + (6.00 * 3) or 50.0.
    my code
    public double pay(double x,int y){
    double sum=0;
    double hours=8.0;
    if(y>hours){
    sum=(y-hours)*(1.5*x) + (hours*x);

    }
    return sum;
    }


    # name expected return your return result
    1 pay(5.5, 6) 33.0 0.0 icon fail
    2 pay(4.0, 11) 50.0 50.0 icon pass
    3 pay(10.0, 40) 560.0 560.0 icon pass
    4 pay(0.25, 7) 1.75 0.0 icon fail
    5 pay(0.0, 20) 0.0 0.0 icon pass
    6 pay(9.0, 0) 0.0 0.0 icon pass

    sigh help me


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help me with beginner coding

    Welcome to the forum! Please read this topic to learn how to post code correctly and other useful info for new members.

    You forgot to program for the case y < hours.

  3. #3
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Help me with beginner coding

    Welcome to the Forum! I'm new too! (actually relearning java XD) I'll see if I can help!
    So X = what the TA is getting paid and Y is the number of hours?

    --- Update ---

    Your problem is you forgot your else statement!
    	// code removed by GB

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help me with beginner coding

    @lil_misfitss: Please review the Forum's policy on Spoon Feeding, The Problem with Spoon Feeding.

    Thanks.

  5. #5
    Junior Member lil_misfitss's Avatar
    Join Date
    Aug 2013
    Location
    USA!!!!!
    Posts
    24
    My Mood
    Confused
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Help me with beginner coding

    Sorry, been a while since i've been on the forum. Forgot about that.

Similar Threads

  1. Replies: 5
    Last Post: April 19th, 2013, 07:59 AM
  2. [SOLVED] I need help with my coding
    By knockturnal22 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: September 16th, 2012, 04:19 PM
  3. Need Help With Coding
    By noles227 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 22nd, 2012, 07:35 PM
  4. Replies: 2
    Last Post: February 19th, 2012, 07:36 AM
  5. Need your help to coding
    By Tony_nguyen19 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 14th, 2011, 08:58 AM