Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-11-2012, 02:38 AM   PM User | #1
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
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?
dannyboi is offline   Reply With Quote
Old 08-11-2012, 03:22 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 08-11-2012, 03:24 AM   PM User | #3
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
So how would I go about branching out?
dannyboi is offline   Reply With Quote
Old 08-11-2012, 03:25 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I don't understand the question. You would use elseif and else clauses to continue evaluating a branch.
Fou-Lu is offline   Reply With Quote
Old 08-11-2012, 03:35 AM   PM User | #5
dannyboi
New Coder

 
Join Date: Jul 2012
Location: NYC
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
dannyboi is an unknown quantity at this point
No, I mean, for it to compile, because when I compile, its like just compiling the main method. Nothing.
dannyboi is offline   Reply With Quote
Old 08-11-2012, 03:40 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
java, java programming

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:38 PM.


Advertisement
Log in to turn off these ads.