• Post Reply Bookmark Topic Watch Topic
  • New Topic

Debugging a basic salary calculator.  RSS feed

 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, I had to write a program for class to request user input for base salary, number of years worked, and total sales. Then use the data to find out the employee's paycheck when including a bonus. I have a few issues with the code, as I have one bug, then it won't calculate anything. Can anyone help me see what I'm missing?



BUG ON LINE 31
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need those braces at Line 31?
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just got rid of them, still no change
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also watch out for the bug on lines 41-47 ... too many ifs.
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got rid of the "if" on line 43, but then a misplaced construct bug on line 42.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using bonus and additionalBonus before assigning any values to them.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:You're using bonus and additionalBonus before assigning any values to them.


That was a good catch.
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh ow you're right. How would I sync them to my "if" statements so that they have those inequality values?
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,

How would I sync them to my "if" statements so that they have those inequality values?


Just move lines 30 - 32 to after the "if" statement block. That said, you will notice that you are never actually printing the payCheck value in lines 30 - 32.

After your "if" statement block has calculating the bonus amounts, then you should be calculated the total payCheck and printing it out. Something like:


Cheers!
Chris
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I moved it but still misplaced construct...

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Good wrote:I moved it but still misplaced construct...

Check the syntax of an if ... else statement
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks mates!
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and unless you are planning to work for Apple, please don't forget the curly brackets....

Behind iPhone’s Critical Security Bug, a Single Bad ‘Goto’
http://www.wired.com/threatlevel/2014/02/gotofail/
 
Dan Good
Ranch Hand
Posts: 49
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Haha yeah that was a huge part of the problem around the if statements. And sorry, an avid non-Apple user.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even after fixing line 38, line 41 will never be executed - probably not what you want.

I'll just mention in passing the employees with 3 or 4 years of service will receive a higher bonus than those with 5+ years of service - that could of course be a strategy for getting folks to quit once they've been around that long :-)
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, Dan. I know this is for class, but in the future, when you write a program that deals with money, remember that your first instinct should be to avoid anything that smells like double or float.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!