Results 1 to 16 of 16
Thread: another noob
- 08-31-2012, 04:17 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Help with if-else-if staement
Hello all and thank you for your time for starters.
My question and problem is i need the applet to re-calculate the compensation in the second else if statement by 0.0375 not 0.025.
what and where am i wrong?
please ignore the comments they are not accurate.
Java Code:// import java libraries import java.text.NumberFormat; import java.util.Scanner; public class Math { // set and declare specific variables double baseSalary = 60000; // set baseSalary double annualSales; // set annualSales double commission, below80 = 0.0, totalCompensation; // set commision to 0 beloew 80% objective double startCompensation = 960000; double commission80, above80 = 0.025, totalCompensation80; // set percentage after 80% is obtained double additionalCompensation = 1200000; double commission100, above100 = 0.0375, totalCompensation100; // set percent above 100% of Sales Goal NumberFormat currency = NumberFormat.getCurrencyInstance(); // Get currency format from import Scanner userInput = new Scanner( System.in ); // Create Scanner to obtain userInput from User // Create userInput, calculator, and final display public void Calculator() { // Get userInput and perform math calculations System.out.print("Enter Salesman Annual Sales: $"); // Display message for userInput annualSales = userInput.nextDouble(); // Read Salary from userInput System.out.println(); // creates blank line commission = annualSales * below80 ; // Total of annualSales below 80% totalCompensation = commission + baseSalary ; // Total compensation // Display Compensation below 80% of sales goal if (annualSales < startCompensation) // Compare annualSales against 960000 { System.out.println(" No extra compensation is offered untill\n the 80% or 960000 goal is reached."); // Display reason for no incentive System.out.println("Therefore the Salesman's Total Annual Compensation of\n " + currency.format(totalCompensation) + " is without any additional incentives."); // Display total compensation } // Display Compensation above 80% of sales goal else if (annualSales >= startCompensation) { commission80 = annualSales * above80 ; // Total of annualSales above 80% totalCompensation80 = commission80 + baseSalary ; // Total commission // Display Commision System.out.println(" Annual Sales Amount of = " + currency.format(annualSales) ); // Display sales amount System.out.println(" Multiplied by = " + above80 + "%"); // Display percent System.out.println(" Gives a Total Commission of = " + currency.format(commission80) ); // Display commision System.out.println("Total Commission Added to Base Salary of = " + currency.format(baseSalary) ); // Display base salary System.out.println("\n Gives the Salesman's\n Total Annual Compensation of = " + currency.format(totalCompensation80) ); // Display total compensation } // Display Compensation above 100% of sales goal else if (annualSales >= additionalCompensation) { commission100 = annualSales * above100 ; // Total of annualSales above 80% totalCompensation100 = commission100 + baseSalary ; // Total commission // Display Commision System.out.println(" Annual Sales Amount of = " + currency.format(annualSales) ); // Display sales amount System.out.println(" Multiplied by = " + above100 + "%"); // Display percent System.out.println(" Gives a Total Commission of = " + currency.format(commission100) ); // Display commision System.out.println("Total Commission Added to Base Salary of = " + currency.format(baseSalary) ); // Display base salary System.out.println("\n Gives the Salesman's\n Total Annual Compensation of = " + currency.format(totalCompensation100) ); // Display total compensation } // End if-else-if Statement } // End Main method } // End class MultiplyLast edited by Blauv; 08-31-2012 at 05:44 PM.
- 08-31-2012, 05:37 PM #2
Re: another noob
Forum Rules -- see the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-31-2012, 05:47 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
sorry for that.
- 08-31-2012, 06:16 PM #4
Re: another noob
Can you explain the problem? What does the code do now that you want to change?i need the applet to re-calculate the compensation
Can you post the current output and add some comments to it to show what you want to change it to.If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 06:21 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
here is the output at present it calculates number above 1,200,000 by 0.025 and should be using 0.0375 instead..
Welcome to the Salesman Annual Compensation Calculator.
Enter Salesman Annual Sales: $1200000
Annual Sales Amount of = $1,200,000.00
Multiplied by = 0.025%
Gives a Total Commission of = $30,000.00
Total Commission Added to Base Salary of = $60,000.00
Gives the Salesman's
Total Annual Compensation of = $90,000.00
Thank you for using the
Salesman Annual Comensation Calculator.
Feel free to use the Calculator anytime!
This should be accomplished in the second else if statement.
- 08-31-2012, 06:35 PM #6
Re: another noob
Are you saying this line:
Multiplied by = 0.025%
should be this:
Multiplied by = 0.0375%
You need to look at the logic of the code where the if tests are and change the logic so it uses the value you want when you want it to.
Can you explain in words what the code is supposed to do? When should it use the value of 0.0375 and when 0.025
Look at the if tests. Hint: If x > 20 it's also > 5Last edited by Norm; 08-31-2012 at 06:41 PM.
If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 06:42 PM #7
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
the code uses the 0.025 from 960000 to 1200000, from 1200000 it needs to use the 0.0375
- 08-31-2012, 06:51 PM #8
Re: another noob
Look at the if tests. Hint: If x > 20 it's also > 5
When will 'do that' be executed? What is executed when x = 30?Java Code:If(x > 5) { do this }else if (x > 20) { do that }Last edited by Norm; 08-31-2012 at 07:36 PM. Reason: changed wording
If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 07:02 PM #9
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
ok, in the first if it test for salary lower then 960000 and multiplies by 0
this works correctly
in the following else if it tests for salary above 960000 and multiplies by 0.025
this works correctly
in the following else if it test for salary above 1200000 and multiplies by 0.0375
this is not working correctly
instead of multiplying by the expected 0.0375 it continues to multiply by 0.025.
that is what i cant figure out. why it wont switch to the 0.0375 for multiplication.
- 08-31-2012, 07:34 PM #10
Re: another noob
Did you see my last post about if tests? Compare the code in that post with this code:
In this code, both do this AND do that will execute when x > 5Java Code:If(x > 5) { do this } if (x > 20) { do that }If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 07:46 PM #11
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
yea i get that, and everything looks like it should work correctly to me.
can u look at above code in the last else if statement to see if u see wjy it wont use the 0.0375 for multiplication?
- 08-31-2012, 07:59 PM #12
Re: another noob
I'm not sure you do.yea i get that
Your code is exactly like this:
What is executed when x = 30?
When will 'do that' be executed? Hint: NeverJava Code:If(x > 5) { do this }else if (x > 20) { do that }
Remember with if /else if / else if /else statements,
the first if that is true will cause the rest of the if statements to be skipped.If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 10:05 PM #13
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
i guess I don't get it then, because from what i can see it does what you say
}else if (annualSales > additionalCompensation)
{
do that
commission100 = annualSales * above100 ; // Total of annualSales above 80%
totalCompensation100 = commission100 + baseSalary ; // Total commission
// Display Commision
System.out.println(" Annual Sales Amount of = " + currency.format(annualSales) ); // Display sales amount
System.out.println(" Multiplied by = " + above100 + "%"); // Display percent
System.out.println(" Gives a Total Commission of = " + currency.format(commission100) ); // Display commision
System.out.println("Total Commission Added to Base Salary of = " + currency.format(baseSalary) ); // Display base salary
System.out.println("\n Gives the Salesman's\n Total Annual Compensation of = " + currency.format(totalCompensation100) ); // Display total compensation
}
- 08-31-2012, 10:15 PM #14
Re: another noob
Look at the code I posted. If x = 30 then the if(x>5) will be true and 'do this' will be executed. 'do that' will never be executed because this test: (x > 5) will be true first.
To test for a range of the values of x, say > 5 and < 20 you need to add another condition to the if statement to test x against its upper value:
if(x > 5 && x < 20)
Write a 10 line program with those if statements and some printlns that print either do this or do that and see what happens.If you don't understand my response, don't ignore it, ask a question.
- 08-31-2012, 10:57 PM #15
Member
- Join Date
- Aug 2012
- Posts
- 8
- Rep Power
- 0
Re: another noob
that makes sense and also fixed the problem.
Thank you!
and im sure ill be talking to you again soon.
- 08-31-2012, 11:04 PM #16
Similar Threads
-
I am a super noob with a super noob question.
By LittleZoppo in forum Java AppletsReplies: 3Last Post: 04-27-2012, 03:50 AM -
Noob Here
By Salamander in forum IntroductionsReplies: 1Last Post: 08-03-2010, 08:19 AM -
Very noob, but need help!!!
By Guilbertda in forum New To JavaReplies: 2Last Post: 02-01-2010, 10:32 PM -
Help im a noob.. a super noob on java..
By critdevil in forum New To JavaReplies: 12Last Post: 03-07-2009, 03:17 AM -
Noob
By nokomis in forum IntroductionsReplies: 2Last Post: 03-06-2009, 05:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks