• Post Reply Bookmark Topic Watch Topic
  • New Topic

Else If Statements  RSS feed

 
James Nobles
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have one set of If Else If statements. My program calculates just the first comboBox. It is retrieving all the values from the other comboBoxes but I do not understand where to place the other If statement structure so I can calculate the other values I have set for the other objects. I would not like to use a different class for each and I know I have my calculations done right below my current if statement. Could it be left there and where shall I place the other if statements so they get read by my arithmetic sequence? Thanks for looking. Please do not refer me to the tutorials I have been reading those all week and my eyes wacko.

 
Campbell Ritchie
Marshal
Posts: 55761
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that other if should be in a different method.
You are not writing object‑oriented code. You have one object handling actions from multiple buttons, which means you do not have single responsibility. You have a method which tries to do too many things all at once. You should have one method for each button, and one listener object for each button. Each actionPerformed method should be short, possibly simply calling another method.

There must be a better way to link sizes and prices than you are using. Maybe a class which encapsulates size and price.

We usually discuss listeners in another forum, so I shall move this thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!