Created
June 20, 2017 21:17
-
-
Save remexre/b531f2ce601217bb846845995579a91d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The main entry point. | |
* | |
* TODO Turn this into a Servlet. | |
*/ | |
public class WhyIHate/*Java*/ { | |
private static final int TWENTY = 20; // Magic numbers are bad. | |
// TODO Create a wrapper class to protect i from invalid accesses. | |
// TODO Create a factory for that wrapper class -- you never know when we | |
// might need to upgrade the data model. | |
private static int i = TWENTY; | |
public static void main(String ... args) { | |
while(i != 1) { | |
// TODO Ideally, we'd hide the math here in an inner class. Or | |
// better yet, create an IIterativeComputation interface and an | |
// AbstractIterativeComputation class implementing it, then a | |
// CollatzIterativeComputation class with a | |
// CollatzIterativeComputationBuilder and/or a | |
// CollatzIterativeComputationFactory to allow for easy | |
// construction. | |
i = i % 2 == 0 | |
? i / 2 | |
: i * 3 + 1; | |
// TODO Create a proper output stream delegate bean interface. | |
System.out.println(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment