public abstract class NumberOfBottlesOfBeerOnTheWall { private NumberOfBottlesOfBeerOnTheWall() { throw new IllegalArgumentException("Not expecting instances of this class."); } public static void singNumberOfBottlesOfBeerOnTheWall(final int numberOfBottles) { if (numberOfBottles >= 0) { printVerseForThisManyBottles(numberOfBottles); singNumberOfBottlesOfBeerOnTheWall(numberOfBottles - 1); } } private static void printVerseForThisManyBottles(final int numberOfBottles) { printNBottlesOfBeer(numberOfBottles, " on the wall. "); printNBottlesOfBeer(numberOfBottles, ". "); if (numberOfBottles > 0) { printTakeOneDownLeaving(numberOfBottles); } else { printNoMoreBottlesToPassAround(); } System.out.println(); } private static void printTakeOneDownLeaving(final int numberOfBottles) { System.out.print("Take " + ((numberOfBottles == 1) ? "it" : "one") + " down and pass it around. "); printNBottlesOfBeer(numberOfBottles - 1, " on the wall."); } private static void printNoMoreBottlesToPassAround() { System.out.print("There are no more to pass around. "); printNBottlesOfBeer(0, " on the wall."); } private static void printNBottlesOfBeer(final int numberOfBottles, final String postfix) { System.out.print(((numberOfBottles == 0) ? "No" : numberOfBottles) + " " + ((numberOfBottles == 1) ? "bottle" : "bottles") + " of beer" + postfix); } }