• Post Reply Bookmark Topic Watch Topic
  • New Topic

Having Trouble figuring out how to get the tax rate to return a value  RSS feed

 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am kinda lost with what exactly I have to pass to get the info out of the constructor with the tax rate.


 
Tushar Goel
Ranch Hand
Posts: 934
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several problems in your code.

variable name should be meaningful. single alphabets are not good option. Also hard to co relate,. Good variable name easy to remember and co relate.

Also, your logic in TaxReturn constructor seems to be confusing.
 
Carey Brown
Saloon Keeper
Posts: 3317
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At line 62

 
Carey Brown
Saloon Keeper
Posts: 3317
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your constructor


First, clean up your indentation. It may help you see the problem with this logic. With your logic the taxRate will ONLY be, either .28, or .3, nothing else.

Next, put this logic into its own helper method, e.g. calcTaxRate(). Your constructor can call calcTaxRate() once income and marriage have been set. You can also call this method from inside setIncome() and setMarriage() to re-calculate the tax rate when either of these changes.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:. . . once income and marriage have been set. . . .
Is that what martialStatus means? And I thought martial meant to do with fighting. There's a Freudian slip if ever I saw one!
 
salvin francis
Bartender
Posts: 1653
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Is that what martialStatus means? And I thought martial meant to do with fighting. There's a Freudian slip if ever I saw one!

I think its a typo for "marital status"
Marital_status
Though there is lot of fighting here too
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


And you shouldn't use the == operator to compare the contents of two String objects. The == operator tests whether two references point to the same object, whereas it's quite possible for two different String objects to contain the same sequence of characters. Use the equals() method of String instead.
 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still new to java is this a cleaner version of indentation? Thank you all for your input! I got it working earlier today!


 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, actually that's very misleading indentation. It implies to the unwary reader that the code starting at line 9 is part of the else-block at line 7. But it isn't. Here's a correctly-indented version:



With this version it's much easier to see that the tax returned from the method is always going to be .28 or .3 regardless of the computations which preceded that part.
 
Carey Brown
Saloon Keeper
Posts: 3317
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or even better yet, add some blank lines
 
Tyson Lindner
Ranch Hand
Posts: 211
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be curious to see how actual tax software implements this sort of thing, but since you're generally asked about marital status early on you're probably looking at two completely separate blocks of code for either single or married. That would require you to repeat code to some extent but I think for this case it would make things a lot less confusing and also make it easier to add the ability to handle random features of tax law that affect just single or just married people.
 
Campbell Ritchie
Marshal
Posts: 56540
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably simply use different sets of allowances or rates depending on “martial” status, and use the same code to process those figures.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!