• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Class code

 
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


This code gives the following output. It works I am just banging my head up against the wall trying to figure out why the annual compensation is so high. I can't figure it out. Any help, suggestions would be eternally grateful!!

run:
What are the total sales?
150000
Your annual income is: $75000.0
If sales target is met compensation is below
$114,375.00 is what you made this year  
Sales Total    Total Annual Compensation
------------------------------------------------------------
Sales: 150000.0  Annual Compensation: 228750.0
Sales: 155000.0  Annual Compensation: 228750.0
Sales: 160000.0  Annual Compensation: 228750.0
Sales: 165000.0  Annual Compensation: 228750.0
Sales: 170000.0  Annual Compensation: 228750.0
Sales: 175000.0  Annual Compensation: 228750.0
Sales: 180000.0  Annual Compensation: 228750.0
Sales: 185000.0  Annual Compensation: 228750.0
Sales: 190000.0  Annual Compensation: 228750.0
Sales: 195000.0  Annual Compensation: 228750.0
Sales: 200000.0  Annual Compensation: 228750.0
Sales: 205000.0  Annual Compensation: 228750.0
Sales: 210000.0  Annual Compensation: 228750.0
Sales: 215000.0  Annual Compensation: 228750.0
Sales: 220000.0  Annual Compensation: 228750.0
BUILD SUCCESSFUL (total time: 5 seconds)
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the formula for annual compensation in non-programming terms?
 
Jason Patton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:What is the formula for annual compensation in non-programming terms?



The current sales target for every salesperson is $140,000.
The sales incentive will only start when 80% of the sales target is met. The current commission is 25% of total sales.
If a salesperson exceeds the sales target, the commission will increase based on an acceleration factor. The acceleration factor is 1.25.
The application should ask the user to enter annual sales, and it should display the total annual compensation.
The application should also display a table of potential total annual compensation that the salesperson could have earned, in $5000 increments above the salesperson's annual sales, until it reaches 50% above the salesperson's annual sales.

Anything less than 112000 does not receive commission. Between 112,000 and 139,999 does receive 25%
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's look at the code you wrote to calculate commision.

What happens if the sales is 100000?
 
Jason Patton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Let's look at the code you wrote to calculate commision.

What happens if the sales is 100000?



Nothing because there is no commission at that point. Anything below 112,000 gains 0 commission.
 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jason Patton wrote:

Knute Snortum wrote:Let's look at the code you wrote to calculate commision.

What happens if the sales is 100000?



Nothing because there is no commission at that point. Anything below 112,000 gains 0 commission.

Look again.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hint: there are two if-statements, not one.
 
Jason Patton
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Hint: there are two if-statements, not one.



Ok so now I changed the statements to look like this:

if (sales <=112000)  //defines parameters for amount of sales
       {
           commission = 0.0;
       }
       
       else if (sales >= 112000 && sales < 140000)  //continues to define parameters for amount of sales.
      {
          commission = 0.25;
       }
       else if (sales > 140000)
   {
       commission = 0.2625;  //declares what to do if either parameter above is not met.
       }
       else
       }
       income = 75000;
{

But that has not changed the outcome of my table whatsoever!
 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Much better. But in your new code, what happens if it is exactly 140000?
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me repost that code with suitable indentation, so that the reader isn't misled:



Actually I don't think that will even compile, there isn't a valid code block after the last "else".
 
Marshal
Posts: 8863
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jason, try the way to start from the largest commision, you should be able to come up with less complex structure of if-then-else statements.
i.e.:
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Outside of the if statement, there is an issue with your calculation:



The second one is inside the loop with the increasing salesTarget.
Note that you are using sales in there and not salesTarget, so the calculation will always be the same.

However, also note that compensation calculation, so the latter one can be rewritten:


Now that doesn't look correct to me...
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to appear a pedantic so‑and‑so, but you have two options for 112000. Look at lines 1 and 5 in Paul C's post. And you have no option for exactly 140000. You won't notice the two occurrences of 112000 because of the else, but things will go horribly wrong if you sell exactly 140000. I like to write if‑elses in order, either ascending or descending, depending on what you do with the boundary values. I also try to use < or > rather than >=/≥ or <=/≤ because the former two are usually easier to read.I think that format is easier to read, and also, if you stick to one operator, there is no risk of missing out values like 140000.
 
reply
    Bookmark Topic Watch Topic
  • New Topic