• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to create a variable to add to?  RSS feed

 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have these two methods that are for a Java Swing project. The first method is supposed to calculate the cost of a computer plus any of the buttons selected in the GUI. My problem is how do I create the variable so that I can add each button to total up on the order?
 
Carey Brown
Saloon Keeper
Posts: 3309
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:So I have these two methods that are for a Java Swing project. The first method is supposed to calculate the cost of a computer plus any of the buttons selected in the GUI. My problem is how do I create the variable order so that I can add each button to total up on the order?
You already have an order, you named it "computer", what you don't have is "extras". You if() statements bail out as soon as one is true so your requirement "any of the buttons selected" is not being met. You shouldn't return until the end of the method.
 
Lexi Turgeon
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You already have an order, you named it "computer", what you don't have is "extras". You if() statements bail out as soon as one is true so your requirement "any of the buttons selected" is not being met. You shouldn't return until the end of the method.


How would I make it so every button will add that value to computer? I can't simple remove the return.
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:. . . How would I make it so every button will add that value to computer? I can't simple remove the return.
I am getting déjà vu about this question. Have you asked something similar before, or was it somebody different? If it was you, what did we tell you at the time? If it wasn't, have you seen that old discussion?
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lexi Turgeon wrote:. . . How would I make it so every button will add that value to computer? I can't simple remove the return.
Yes, you can remove the return. You have to remove it. Or at least most occurrences.

Stop coding. You need pencil and paper. Write down how you would work out the cost of buying a computer by hand. How would you work out the different components of the price?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!