• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assigning to Doubles  RSS feed

 
Thomas Johnson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working with doubles I'm trying to figure out how to set this up so it works?

I'm just stuck on how to set and Assign a double FedTaxWitholding that gets the Fed Tax Withholding = Gross Pay * Fed
Tax Withholding Rate.

Do I need a string for Gross pay?
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Variable names begin with a lower-case character. fedTaxWithholding = grossPay * fedTaxWithholdingRate. Where all variables are double.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

No, you mustn't use a String in those circumstances. Only primitives can use the * operator.
You shouldn't use doubles for money anyway. you should use integers (and denominate the amounts in pence cents or similar) or BigDecimal.
 
Thomas Johnson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie

Unfortunately, this is my homework assignment and I agree everything I have seen has int
 
Thomas Johnson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what I have so far?



 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always use code tags; I have added tags to your post and corrected your indenting and doesn't it look better.

You have a good start with the parseDouble method but that only works when the text you are parsing looks like a number. The method will not take kindly to being asked to parse a name Besides, the name is already a String, so you don't need to change it in the first place.
Does that code actually compile? I thought you need an argument before the String for option pane. That shows which GUI component you want the option pane to appear in front of. You don't seem to have any GUI components, so you would need null as the first argument. That makes the option pane appear in the centre of the screen. Beware: I have sometimes found my option panes in the centre of the screen but behind everything else. Look closely at the task bar if you can't find them.
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have had another look at option pane and this method will probably do what you want without your having to write null.
 
Thomas Johnson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks a lot better but my eclipse show error on my dblFedtax line so that can't be right?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37462
537
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas Johnson wrote:It looks a lot better but my eclipse show error on my dblFedtax line so that can't be right?

What error is it? If you look at the Problems view, in Eclipse, you can see the actual error.

Also, pay attention to the data types. Does parseDouble() take a String or double as a parameter? Which are you passing?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!