• 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

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

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 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

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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:. . .
How about something like:

Let's get rid of the magic numbers:-
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic