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 6 of 6

Thread: help with profitMargin (If/else structuring)

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

    Default help with profitMargin (If/else structuring)

    solved.
    Last edited by ryuumaru; June 28th, 2014 at 01:48 PM. Reason: solved.


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

    Default Re: help with profitMargin (If/else structuring)

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.
    I cannot get it print when sales are MET/EXCEEDED(When all the total profit margin of the sales for all 4 quarters is greater than or equal to 20.
    Where in the code are you trying to do this part?

    You should comment your if/else branches to describe the purpose of each branch.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with profitMargin (If/else structuring)

    Apologies, the part where I need help is on the "if else"

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

    Default Re: help with profitMargin (If/else structuring)

    As I said, comments would help you to keep the logic straight AND to let someone else reading your code know what it is supposed to be doing. For example:
        // for less than a full year of sales data
        if(noOfQtrs < 4)
        {
            // if sales goals have been met
            if(profitMargin >= 20)
            {
                System.out.printf("\nKeep up the GOOD work and a possible year-end bonus!");
            }
            // when sales goals have not been met
            else{
                System.out.printf("\nSo far sales are lagging behind projections."); //PRINT3
            }
        }//END IF(noOfQtrs <4)
     
        // for a full year of sales data and the sales goals have not been met
        else if(profitMargin <= 20)
        {
            System.out.printf("\nIt’s been a GOOD year. Thank you for all your hard work!\n"
                    +"\nEmployees qualify for a 5% year end bonus!!!");
        } //END IF
     
        // for a full year of sales data and the sales goals have been met
     
        System.exit(0);
    Assuming the comments I've added correspond to the logic you're trying to code, I believe you're missing the statement that goes with the last comment. Plus it seems the last else/if you have coded where the profitMargin is <=20 is inconsistent with the message that it's been a GOOD year. Did you get that condition backwards?

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with profitMargin (If/else structuring)

    yes I did get the last condition backwards. it was also supposed to be greater than or equal to. I edited it.

    thank you for pointing that out, but it still won't print the printf statement for " System.out.printf("\nIt’s been a GOOD year. Thank you for all your hard work!\n"
    +"\nEmployees qualify for a 5% year end bonus!!!");"

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

    Default Re: help with profitMargin (If/else structuring)

    Please post the updated code.

    To get to the print statement you've indicated (thanks for finally being specific), the first if() condition must be FALSE ( >= 4 ) and the corresponding else/if() statement must be TRUE. I believe you've changed this latter condition to:

    else if ( profitMargin >= 20 )

    If the print statement you want to print is never being executed, debug your code to find out why the first and latter conditions are never FALSE and TRUE, respectively, at the same time. Add print statements to output the values of the condition statement variables if you need to, but these statements are pretty basic, and you should be able to trace the results by inspection.

Similar Threads

  1. Simple chess program (no AI) - Need help with structuring my code
    By MineeMo in forum Object Oriented Programming
    Replies: 6
    Last Post: June 18th, 2012, 10:12 AM