• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can not get my method to return correct values in "if statements"  RSS feed

 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So for this I am looking to have a button selected and if that button is selected (or multiple buttons selected) the program will add the value of the computer to any of the other items selected. My code is saying that my returns are incorrect and I can not figure out why.



Here is my compiler error that NetBeans gives me:

 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable computer is a type double and the variable extraKeyboard is a check JCheckbox.  There's no way to "add" the two.

The method prices() is confusing you, I think.  It can be removed; it's doing nothing.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:The variable computer is a type double and the variable extraKeyboard is a check JCheckbox.  There's no way to "add" the two.

The method prices() is confusing you, I think.  It can be removed; it's doing nothing.


How would I make it so that I can give each of the check boxes and the computer a value so I can add them together. I have to use the applet to calculate shipping so each of the checkboxes having a number value is crucial.
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do checkboxes have numbers in? I thought they only had ✓ in.
Do you have a Computer class? Can you set its components so the getDvdDrive method returns the price of a DVD drive (or 0 as appropriate)?
Why do you have a method where you are setting the values of the parameters (lines 9‑20)? Or is the the method you have been told to delete? Why are you mixing double arithmetic and integer arithmetic?
Don't use double arithmetic for anything involving money. Use BigInteger, or alternatively, denominate everything in whole numbers and use integer arithmetic.

What you are doing in the next method is going through the options and terminating the adding process as soon as you find one which has been selected. You want to go through the whole lot and not return anything until you have done all the additions. That will of course give you a total, not numbers in checkboxes.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Do checkboxes have numbers in? I thought they only had ✓ in.
Do you have a Computer class? Can you set its components so the getDvdDrive method returns the price of a DVD drive (or 0 as appropriate)?
Why do you have a method where you are setting the values of the parameters (lines 9‑20)? Or is the the method you have been told to delete? Why are you mixing double arithmetic and integer arithmetic?
Don't use double arithmetic for anything involving money. Use BigInteger, or alternatively, denominate everything in whole numbers and use integer arithmetic.

What you are doing in the next method is going through the options and terminating the adding process as soon as you find one which has been selected. You want to go through the whole lot and not return anything until you have done all the additions. That will of course give you a total, not numbers in checkboxes.


The checkboxes do not have numbers in them, it is in fact a check mark. I want to make it so that when a check box is chosen, and the type of shipping is chosen, the applet calculates the total for the items chosen and calculates the shipping based on those items all together.
 
Knute Snortum
Sheriff
Posts: 4270
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:How would I make it so that I can give each of the check boxes and the computer a value so I can add them together. I have to use the applet to calculate shipping so each of the checkboxes having a number value is crucial.

How about something like:
 
Campbell Ritchie
Marshal
Posts: 56521
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:. . .
How about something like:
Let's get rid of the magic numbers:-
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!