This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Trying to get rid of redundancy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trying to get rid of redundancy?" Watch "Trying to get rid of redundancy?" New topic
Author

Trying to get rid of redundancy?

Ashley Kin
Ranch Hand

Joined: Oct 18, 2011
Posts: 36
Hi, I'm trying to get rid of redundance in this program by factoring? Thank you for any help! (Sorry, I'm not sure how to use clipboard)


Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7492
    
  18

Ashley Kin wrote:Hi, I'm trying to get rid of redundance in this program by factoring?

Well, the usual way is to put repeated code into a method and call it instead. And it seems like you have 2 big blocks of repeated code. You might want to think about parameter(s) for that method as well, so that it's self-contained.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
another way is not to post the same question in two forums. You've got this same one in "Java in General".

rc
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287

Ralph Cook wrote:another way is not to post the same question in two forums. You've got this same one in "Java in General".

rc


good sense of humor!
Sven Eriksson
Greenhorn

Joined: Oct 20, 2011
Posts: 1
Hi Ashley

Easiest would be something like this:



Hopefully that might help some, but you could also write it in another method and call to it
Remember, everyone codes differently...
 
Don't get me started about those stupid light bulbs.
 
subject: Trying to get rid of redundancy?
 
Similar Threads
Calculating the distance between two points problem
How to return value back to main?
Getting rid of redundancy?
How should I split up this big method? Still need help please!
Please help