Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Does not show the if statements in any way?

    import javax.swing.JOptionPane;
    public class Main{





    public static void main(String[] args) {
    // declare your variables still
    int salesTotal = 5;
    double commissionRate = 10;
    int salesClass = 10;

    if (salesTotal < 10000) {
    if (salesClass == 1)
    commissionRate = 0.02;
    }
    else if (salesClass == 2) {
    commissionRate = 0.025;
    JOptionPane.showMessageDialog(null, "Commission is " + commissionRate+salesClass+salesTotal);
    }

    }
    }

    Will not show me the if statements. Is it the fact I forgot to put in the InputMethod?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Given the salesTotal and salesClass variables you have here, you have no branch to follow which results in any processing with the values provided. You do match salesTotal < 10000, but you do not match salesClass == 1. There is no else or elseif off of this branch, so no further action is taken and you exit the branch. There is no processing instructions beyond this point.

  • #3
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts
    So how would I go about branching out?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't understand the question. You would use elseif and else clauses to continue evaluating a branch.

  • #5
    New Coder
    Join Date
    Jul 2012
    Location
    NYC
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No, I mean, for it to compile, because when I compile, its like just compiling the main method. Nothing.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Yes, but you won't receive any output. You haven't specified a set of branch evaluations that actually lead to any useful processing or output, so it performs no tasks when run.
    Look at your branch statements. You have this:
    Code:
    if (salesTotal < 10000) // this is true
    { 
        if (salesClass == 1) // this is false
        {
        }
        // you are here.
    }
    else if (salesClass == 2) // will never get here.
    {
        // output
    }
    Look at where you are there. Since there is no satisfied condition it abandons the inner branch and returns to the outer branch. The outer branch provides no else, so it has no condition to satisfy and continues processing. There is no following instruction.

    The only way you will ever get output in this is if salesClass is set to 2.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •